在Laravel中更新并上传图片后收到错误消息。
InvalidArgumentException
控制器
public function actedit(Request $Request, $id)
{
$user = User::find($id);
$user->title = $Request->input('title');
$user->description = $Request->input('description');
$user->url = $Request->input('url');
$file = $Request->file('avatar');
if (!$file) {
return redirect()->route('editprofile')->with('alert', 'foto harus diisi!');
}
$file_name = $file->getClientOriginalName();
$path = public_path('/img');
$file->move($path, $file_name);
$user->image = 'public/img/'.$file_name;
$user->save();
return redirect('profile/'.$id);
}
路线
Route::post('/edit/{id}', 'HomeController@actedit')->name('actedit');