我是一名新手,正在使用Laravel 5.3版本。我尝试过搜索但并没有发现我的错误所在。我的视图中一直显示“Undefined variable: user”,同时我也在进行表单模型绑定。手动输入URL进行模型绑定可以正常工作,但无法通过点击链接打开编辑视图。
我的路由如下:
Route::get('/profile/edit/{id}', 'ProfileController@getEdit');
Route::post('/profile/edit/{id}', 'ProfileController@postEdit');
我的控制器:
public function getEdit($id){
$user= User::findOrFail($id);
return view('profile.edit', compact('user'));
}
我的看法:
<li><a href="{{ url('/profile/edit', $user->id ) }}">Update profile</a></li>
我的表格:
{!! Form::model($user,['method' => 'POST', 'action'=> ['ProfileController@postEdit', $user->id]]) !!}