Error uploading images in laravel to database

0

I'm trying to upload an image to the database from a form

This is my view

{{ Form::open(array('url' => '/saveAbsence'), ['id' => 'absenceForm'], ['enctype'=>'multipart/form-data']) }}
{{Form::file('cover_image')}}
{{Form::close()}}

This is my driver

public function storage(imageRequest $request){
       $image = $request->file('cover_image');
       $file = $image->store('img');

       $request->merge(['image'=> $file]);
       $cover = product::create($request->all());
}

But I get this error

"message": "Call to a member function store() on null"
    
asked by gmrYaeL 13.11.2018 в 14:27
source

1 answer

0

The error is that the $ cover variable gets an array with several files that may have been uploaded, so you must change

$cover = product::create($request->all());

for

$cover = product::create($request->first());

which does return a single object, and if you want to traverse the entire array, you must cycle from 0 to the length of the array.

Greetings!

    
answered by 14.11.2018 в 19:23