在laravel中更新时调用成员函数move()的空值
我在尝试更新数据时出错。如果我更新图像,则不会出现错误,但如果我没有更新图像,则会在null上显示对成员函数move()的调用 这是我的代码:在laravel中更新时调用成员函数move()的空值,laravel,Laravel,我在尝试更新数据时出错。如果我更新图像,则不会出现错误,但如果我没有更新图像,则会在null上显示对成员函数move()的调用 这是我的代码: public function update($id, Request $request) { $change = Profile::findorfail($id); $before = $change->foto_profil; $profile = [ 'fullname' =&g
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);
}
请参阅文档您可以使用
hasFile()
方法确定请求中是否存在文件:
if($request->hasFile('foto_profil')){
$request->foto_profil->move(public_path().'/image', $before);
}
请参阅文档如果请求中存在照片,只需添加验证即可
if($request->foto_profil) {
$request->foto_profil->move(public_path().'/image', $before);
}
如果请求中存在照片,只需添加验证
if($request->foto_profil) {
$request->foto_profil->move(public_path().'/image', $before);
}
谢谢它成功了谢谢它成功了