[英]ErrorException (E_ERROR) Undefined variable: age (View: /home/....profile.blade.php)
I am getting an error on a recycled code which works perfectly fine in another section of the app..我在回收代码上遇到错误,该代码在应用程序的另一部分运行良好。
Controller :控制器 :
public function edit($id)
{
$user = User::findOrFail($id);
$gender = Gender::pluck('name', 'id')->all();
$age = Age::pluck('group', 'id')->all();
return view('profile', compact('user', 'gender', 'age'));
}
View :看法 :
<div class="form-group">
{!! Form::label('age_id', 'Age Group: ') !!}
{!! Form::select('age_id', $age, null, ['class'=>'form-control']) !!}
</div>
Request :要求 :
public function authorize()
{
return Auth::check();
}
public function rules()
{
return [
// 'name' => 'required|string|min:4|max:40',
// 'email' => 'required|string|email|min:8|max:40|unique:users',
// 'photo_id' => 'required',
// 'gender_id' => 'required',
// 'age_id' => 'required',
// 'password' => 'required|string|min:8|max:16'
];
}
In the "compact()" function, you are passing 3 variables as a string:在“compact()”函数中,您将 3 个变量作为字符串传递:
return view('profile', compact('user', 'gender', 'age'));
You have to pass them inside an array:您必须将它们传递到数组中:
return view('profile', compact(['user', 'gender', 'age']));
I will have to see the Model if this doesn't fix the bug, but for now is the only thing that I can see.如果这不能修复错误,我将不得不查看模型,但现在是我唯一能看到的东西。 Let us know the results.
让我们知道结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.