嘿我试图通过向控制器发送id来更新用户配置文件。每次我提交表单时,都会给我错误的参数。我已经在我的控制器函数中定义了路由并包含了id参数,但是我得到了错误。
我的控制器的代码是
public function update_avatar(Request $request,$id)
{
$this->validateInput($request);
$u = User::findOrFail($id);
dd($u);
//Handle the user upload of avatar
if($request->hasFile('avatar'))
{
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300,300)->save(public_path('/uploads/'.$filename));
}
$user = Auth::user();
$user->name = $request->name;
dd($user->name);
$user->email = $request->email;
if($request->password == null)
{
$user->password = $u->password;
}
$user->password = $request->password;
$user->avatar = $filename;
$user->role = 'admin';
$user->save();
return view('/adminPanel/adminProfile',array('user' => Auth::user()));
}
我的观点代码
<form class="form-horizontal" role="form" enctype="multipart/form-data" action="{{ route('profile', ['id' => $user->id]) }}" method="post">
我的路线是
Route::post('/adminPanel/id/adminProfile',
'AdminProfileController@update_avatar')
->name('profile')->middleware('admin');;
答案 0 :(得分:2)
在您的路线中使用。你缺少括号。使用route传递id或任何值时,必须使用括号。
Route::post('/adminPanel/{id}/adminProfile','AdminProfileController@update_avatar')->name('profile')->middleware('admin');