错误:在字符串上调用成员函数storeAs()

时间:2019-01-28 00:22:29

标签: laravel laravel-routing laravel-request

public function cadastraAutomovelHomeAdd(Request $request)
{
    $file = $request->arquivo;
    $upload = $request->arquivo->storeAs('products', 'novonomeaffffff.jpg');
    exit();
}

表格

<form method='post' action='/cadastrar' enctype="multipart/form-data">
    {{ csrf_field() }}
    <div>
        <h5>Placa do Veículo:</h5>
    </div>
    <input type="file" class="form-control" name='arquivo' required placeholder="IMAGEM DO VEÍCULO">
    <input type='submit'/>
</form>

路线

Route::post('/cadastrar','Automovel@cadastraAutomovelHomeAdd');

我提交了表单,但出现以下错误。

  

在字符串上调用成员函数storeAs()

1 个答案:

答案 0 :(得分:2)

您需要将其包装为文件才能访问文件方法,例如:

$upload = $request->file('arquivo')->storeAs('products', 'novonomeaffffff.jpg');

https://laravel.com/docs/master/filesystem#storing-files