Php laravel 5.3上传文件

Php laravel 5.3上传文件,php,laravel,laravel-5.3,Php,Laravel,Laravel 5.3,我使用的是Laravel5.3,我想上传一个文件到一个目录。我一直遵循laravel文档上传文件,如以下代码: public function store(Request $request) { $path = $request->attachment->store('attachment'); } 但它得到了一个错误 对字符串调用成员函数store() 在Laravel5.2之前,我一直在使用这段代码来上传文件和它的工作 if ($request->hasFile(

我使用的是Laravel5.3,我想上传一个文件到一个目录。我一直遵循laravel文档上传文件,如以下代码:

public function store(Request $request)
{
    $path = $request->attachment->store('attachment');
}
但它得到了一个错误

对字符串调用成员函数store()

在Laravel5.2之前,我一直在使用这段代码来上传文件和它的工作

if ($request->hasFile('attachment')) {
    $destination = 'upload/attachment';
    $file = $request->file('attachment');
    $file->move($destination, $file->getClientOriginalName());
}

$filelocation = $destination. "/" .$file->getClientOriginalName();
但在Laravel5.3中,它不起作用,我得到一个错误

未定义变量:目标

你能帮我解决我的代码有什么问题吗

public function store(Request $request)
{
    $path = $request->attachment->store('attachment');
}
我不认为
$request->attachment
做了你想做的事情。将该行更改为:

$request->file('attachment')->store('/your/destination/path')


$request->hasFile('attachment')
false
时,
$destination
将不会被声明。因此,当它到达
$filelocation
行时,您会得到一个未定义的变量。

在Larave 5.3中,您可以使用如下简单的上载文件:

$request->file('file')->storePublicly($folderSrc);

这将您的文件保存到storage/app/public/you文件夹src

hi,首先,我一直在使用$request->file('attachment')->store('storage/attachment');但是它对null上的成员函数store()进行错误调用,这意味着file()方法没有返回任何内容。检查您是否正在上载一个名为“附件”的文件。我已将输入名设置为“附件”是真的吗?
$request->file('file')->storePublicly($folderSrc);