Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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
Php 什么';在Laravel 7中存储和更新图像的最佳方式是什么?更新图像时在laravel中对null调用成员函数move()?_Php_Laravel_Forms_Request_Backend - Fatal编程技术网

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

Php 什么';在Laravel 7中存储和更新图像的最佳方式是什么?更新图像时在laravel中对null调用成员函数move()?,php,laravel,forms,request,backend,Php,Laravel,Forms,Request,Backend,我用这种方法来存储图像,有没有其他方法来缩短代码,当存储图像和更新图像时,最好的方法是什么,因为当我用它来更新时,我得到了这个错误 在laravel中调用null上的成员函数move() $file_extension = $request ->photo -> getClientOriginalExtension(); $file_name = time().'.'.$file_extension; $path = 'images/'; $request -> photo -

我用这种方法来存储图像,有没有其他方法来缩短代码,当存储图像和更新图像时,最好的方法是什么,因为当我用它来更新时,我得到了这个错误

在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);
第二步是更改图像名称

第三步是移动或存储图像


$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);

这毫无意义。如果
$request->photo
null
,则
$request->photo->getClientOriginalExtension()
应引发类似错误。你确定你没有在什么地方打错字吗?那我该怎么办