[英]ErrorException (E_NOTICE) Trying to get property of non-object
[英]ErrorException (E_NOTICE) Undefined variable: user
未定義變量:用戶值未更新..
ProfilesController.php 文件....
public function edit(User $user)
{
return view('profiles.edit',compact('user'));
}
public function update()
{
$data= request()->validate([
'title' =>'required',
'description'=>'required',
'url'=>'url',
'image'=>'',
]);
$user->profile->update($data);
return redirect("/profile/{$user->id}");
}
web.php文件......
Route::get('/profile/{user}/edit', 'ProfilesController@edit')->name('profile.edit');
Route::patch('/profile/{user}', 'ProfilesController@update')->name('profile.update');
您沒有在路由模型綁定的update
方法中接受User
,就像您在其他端點上一樣。 嘗試更改您的更新方法
public function update()
到
public function update(User $user)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.