简体   繁体   中英

ErrorException (E_NOTICE) Undefined variable: user

Undefined variable: user Values are not updating..

ProfilesController.php file....

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 file......

Route::get('/profile/{user}/edit', 'ProfilesController@edit')->name('profile.edit');
Route::patch('/profile/{user}', 'ProfilesController@update')->name('profile.update');

You are not accepting the User within the update method for route model binding, like you are on the other endpoints. Try changing your update method from

public function update()

to

public function update(User $user)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM