1

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?

19
  • Your multiStepStore controller works fine?
    – STA
    Commented Jul 27, 2020 at 7:32
  • @STA Yes I' m getting all column values including "img_path" that stores the names for all images. Now I want to show all images into blade.
    – Shaan
    Commented Jul 27, 2020 at 7:36
  • Make php artisan storage:link then {{ asset('storage/uploads/' . $img) }}
    – STA
    Commented Jul 27, 2020 at 7:39
  • You stored your image inside /storage/uploads, which is not a public directory. The public directory is /storage/app/public. Now php artisan storage:link will work
    – STA
    Commented Jul 27, 2020 at 7:43
  • @STA It's showing broken thumbnail. In console, it returns all the stored image names in link like http:://(webite)/storage/uploads/img1,img2,img3
    – Shaan
    Commented Jul 27, 2020 at 7:43

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.