Reputation: 483
I have a form to upload multiple images. I have stored multiple image names into database while in Laravel, I'm using local storage storage/upload to upload my images.
Now I want to call them one by one. The solution I had in my mind didn't work. I need logic to call all images.
Controller
public function multiStepStore(Request $request)
{
if($request->hasFile('photos')) {
$files = $request->file('photos');
foreach ($files as $file) {
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
Storage::disk('local')->put($filename, File::get($file));
$filepath[] = $filename; // Store all Images into array
$getAllImages = collect($filepath)->implode(',');
}
}
}
Blade
<tr>
<td>Location</td>
<td>{{ $row->location}}</td>
</tr>
<tr>
<td>Images</td>
<td>
@foreach( (array) $row->img_path as $img)
<img src=" asset('storage/uploads/' .{{ $img }}">
@endforeach
</tr>
The output is just a broken image thumbnail. How can I get all images?
Upvotes: 1
Views: 1852
Reputation: 34678
You stored your image inside /storage/uploads
, which is not a public
directory. The public directory is /storage/app/public
. move all your /storage/uploads
files to /storage/app/public/uploads
, then create a symbolic link as :
php artisan storage:link
Change your blade code like this :
@php
$x = explode (",", $row->img_path);
@endphp
@foreach($x as $key => $val)
<img src="{{ asset('storage/uploads/' . $val) }}">
@endforeach
Upvotes: 1