【问题标题】:Error: Call to a member function storeAs() on string错误:调用字符串上的成员函数 storeAs()
【发布时间】:2019-06-20 23:51:40
【问题描述】:
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()

【问题讨论】:

    标签: laravel laravel-routing laravel-request


    【解决方案1】:

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

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

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

    【讨论】:

    • 我不懂克里斯,请给我写正确的代码?请
    • 我有,就在上面吗?你有-&gt;arquivo,但它应该是-&gt;file('arquivo')
    • Cris 你的代码错误:在 null 上调用成员函数 storeAs()
    • 不是我的代码伙伴。上述错误虽然表明arquivo 不包含任何上传的数据,但您确定要上传文件吗?尝试使用 dump($request-&gt;all()) 之类的方式转储请求数据
    • "_token" => "AltCjFjNN3FfZU8xhdjSE9M5ki6bxnAnmStZhDW8" "arquivo" => "download.png" "placa" => "w" "marca" => "w" "modelo" => "e" "cor" => "f" "tipcombust" => "r" "nportas" => "4" "quilometragem" => "22" "renavam" => "wqdqw" "chassi" => "wqd" "valordiaria " => "222" ]
    猜你喜欢
    • 1970-01-01
    • 2017-12-17
    • 2022-11-10
    • 2017-03-24
    • 2019-02-11
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    相关资源
    最近更新 更多