在 Laravel 7 中存储和更新图像的最佳方式是什么?更新图像时在 laravel 中的 null 上调用成员函数 move()?

what's the best way to store and update the images in Laravel 7? Call to a member function move() on null in laravel when update image?

我正在使用这种方式来存储图像,是否有另一种方法来缩短此代码,存储图像和更新图像的最佳方式是什么,因为当我使用它来更新时,我收到此错误

在 laravel

中对 null 调用成员函数 move()
$file_extension = $request ->photo -> getClientOriginalExtension();
$file_name = time().'.'.$file_extension;
$path = 'images/';
$request -> photo -> move($path,$file_name);

user::create([
    'photo' => $file_name,

]);

你能帮帮我吗

首先验证图像

第二步是修改图片名称

第三步移动或存储图像


$request->validate([
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);
    
        $imageName = time().'.'.$request->image->extension();  
     
        $request->image->move(public_path('images'), $imageName);