如何修复"Call to a member function store() on null"?



我正在将图像上传选项设置为文件夹。是什么原因以及如何解决此错误?

MessageController中的PHP

public function store(Request $request)
{
    $request->image->store('comments');
}

html

<form action="/api/messages" enctype="multipart/form-data" method="post">
    Select image to upload: 
    <input id="fileToUpload" name="fileToUpload" type="file"> 
    <input name="submit" type="submit" value="Upload Image">
</form>

我期望输出200,但是获得服务器错误500。

我相信您没有在请求中正确引用图像文件。相反,请尝试这样做:

$request->file('fileToUpload')->store('comments');

相关内容

最新更新