PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 15, 2022

[FIXED] How to fetch multiple Images into blade in Laravel

 November 15, 2022     laravel, laravel-6, php     No comments   

Issue

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?


Solution

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


Answered By - sta
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing