Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在laravel中更新时调用成员函数move()的空值_Laravel - Fatal编程技术网

在laravel中更新时调用成员函数move()的空值

在laravel中更新时调用成员函数move()的空值,laravel,Laravel,我在尝试更新数据时出错。如果我更新图像,则不会出现错误,但如果我没有更新图像,则会在null上显示对成员函数move()的调用 这是我的代码: public function update($id, Request $request) { $change = Profile::findorfail($id); $before = $change->foto_profil; $profile = [ 'fullname' =&g

我在尝试更新数据时出错。如果我更新图像,则不会出现错误,但如果我没有更新图像,则会在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);
}

请参阅文档

您可以使用
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);
}

谢谢它成功了谢谢它成功了