I've form in my website. Out of many fields, there is one field that let users allow to upload multiple images. I want to save the path for all images into database so that I can show them back on blade file. I can upload images and images are stored into my local storage but the issue I get only one path and that is saved into database.
I want to store all paths separately into database so that I could access them for Blade. How can I do that?
Blade
<form method="POST" enctype="multipart/form-data" action="{{route('form.multiStepStore')}}">
@csrf
<input type="file" class="form-control" name="photos[]" multiple />
......
</form>
Controller
public function multiStepStore(Request $request)
{
if($request->hasFile('photos')) {
$allowedfileExtension = ['jpg', 'png', 'jpeg'];
$files = $request->file('photos');
foreach ($files as $file) {
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$filepath = $filename.'.'.$extension;
Storage::disk('local')->put($filename.'.'.$extension, File::get($file));
}
$store_seller = new Sellers();
$store_seller->img_path = $filepath;
dd($filepath); //Returns only one path out of let's say 3 images
}
}
Laravel 7. PHP 7.4.