Ad

Error: Call To A Member Function StoreAs() On String

- 1 answer

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

Form

<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

Route::post('/cadastrar','[email protected]');

I submit the form, and I get the following error.

Call to a member function storeAs() on string

Ad

Answer

You need to wrap it as a file to access the file methods, something like:

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

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

Ad
source: stackoverflow.com
Ad