尝试更新数据时出现此错误。如果更新图像,则没有错误,但是如果没有更新,则显示在null上调用成员函数move()
这是我的代码:
public function update($id, Request $request)
{
$change = Profile::findorfail($id);
$before = $change->foto_profil;
$profile = [
'fullname' => $request['fullname'],
'phone' => $request['phone'],
'ttl' => $request['ttl'],
'foto_profil' => $before
];
$request->foto_profil->move(public_path().'/image', $before);
$change->update($profile);
return redirect('/profil');
}
您可以使用以下方法确定请求中是否存在文件hasFile()
:
if($request->hasFile('foto_profil')){
$request->foto_profil->move(public_path().'/image', $before);
}
在这里查看文档
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句