1
People I have the code below in Laravel that saves a single image and works correctly. But I would like to save multiple images that come from an input that is named:"name[]" Multiple. I think I would need a go but I couldn’t make it work.
public function store(Request $request)
{
$input = $request->all();
$modality = new Modality($input);
$modality->save();
$image = $request->image; //Array de imagens
$imageName = $image->getClientOriginalName();
$image = new Image();
$image->name = $imageName;
$image->imageable_id = $modality->id;
$image->imageable_type = Modality::class;
$path = $request->file('image')->storeAs('public', $imageName);
$image->save();
return redirect()->action('ModalityController@index');
}
In your code is giving error in $file.
– Marcelo
I changed it to: $path = $value->storeAs('public', $value->getClientOriginalName()); and it worked.
– Marcelo
@Marcelo is
$im
actually it was a typo.!– novic
Right. It worked, thank you.
– Marcelo