简体   繁体   English

ErrorException (E_NOTICE) 未定义变量:用户

[英]ErrorException (E_NOTICE) Undefined variable: user

Undefined variable: user Values are not updating..未定义变量:用户值未更新..

ProfilesController.php file.... 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 file...... web.php文件......

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.您没有在路由模型绑定的update方法中接受User ,就像您在其他端点上一样。 Try changing your update method from尝试更改您的更新方法

public function update()

to

public function update(User $user)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ErrorException (E_NOTICE) 试图获取非对象的属性 - ErrorException (E_NOTICE) Trying to get property of non-object E_NOTICE:仅报告未定义的变量 - E_NOTICE: Report only undefined variables Laravel 中的 ErrorException (E_NOTICE) 数组到字符串的转换 - ErrorException (E_NOTICE) Array to string conversion in Laravel 处理对未定义索引和 E_NOTICE 的赋值 - Handling assignment to undefined index and E_NOTICE 数组中的未定义变量没有E_NOTICE吗? - No E_NOTICE for undefined variables in array? 如何在simpleTest中捕获“未定义的索引”E_NOTICE错误? - How to catch an “undefined index” E_NOTICE error in simpleTest? E_NOTICE和多维数组的未定义索引错误 - E_NOTICE and Undefined index error with multidimensional arrays ErrorException (E_NOTICE) 试图获取非对象的属性“default_locale”。 我似乎无法在这里找到问题 - ErrorException (E_NOTICE) Trying to get property 'default_locale' of non-object. I cannot seem to find the problem here 我得到“ErrorException(E_NOTICE)试图获取非对象的属性”试图运行一个cron作业脚本 - Am getting “ErrorException (E_NOTICE) Trying to get property of non-object” trying to run a cron job script ErrorException [注意]:未定义的偏移量:1 - ErrorException [ Notice ]: Undefined offset: 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM