Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gustav1105's avatar

How to display Image saved in storage folder on blade

I would like to display an image saved in storage directory in a blade view, with the path stored to the database

I am storing the file successfully to the storage/app/public folder and writing the path to the database like so

$imagePath = $request->file('image')->store('public');
    $image = Image::make(Storage::get($imagePath))->resize(320,240)->encode();
    Storage::put($imagePath,$image);

    $myTheory->image = $imagePath;

Now I would like to retrieve the image to use in my index.blade.php file like so

      <div class="panel-body">
              {{ $myTheory->description }}
              <!-- CODE GOES HERE FOR THE IMAGE SOURCE-->

              <img src="storage/app/{{ $myTheory->image}}"></img>

              <div class="panel-footer">
              {{ $myTheory->updated_at }}
            </div>
            </div>

Obviously the above code does not work because I am trying to access the storage folder from the view

in my page source i have this


              <img src="storage/app/public/9c9805d15667f17720ab79638e94b824.jpeg"></img>

The laravel documentation states use storage link in my terminal I did this

php artisan storage:link
The "public/storage" directory already exists.

This tells me the storage link has been created for storage\app\public and public\storage

further the laravel documentation states use the asset helper so in my blade file I did this but it does not work

    <div class="panel-body">
              {{ $myTheory->description }}
              <img src="<?php echo asset("storage/app/$myTheory->image")?>"></img>
              <div class="panel-footer">
              {{ $myTheory->updated_at }}
            </div>
            </div>

and in the page source i get the full qualifying path to storage directory

<img src="http://dev.flatearthexperiment.com/storage/app/public/9c9805d15667f17720ab79638e94b824.jpeg"></img>

But there is no image loading to the view!

What am I doing wrong and how to fix!

See laravel documentation for what I used https://laravel.com/docs/5.3/filesystem#the-public-disk

navigate to public disk.

Any and all help welcome THANKS!

0 likes
14 replies
usman's avatar
usman
Best Answer
Level 27

@gustav1105 this line:

<img src="<?php echo asset("storage/app/$myTheory->image")?>"></img>
//should be changed to
<img src="<?php echo asset("storage/$myTheory->image")?>"></img>

then it will work.

4 likes
oliverlop's avatar

@usman worked for me, i had issues because the app in question was moved from cpannel to hestia then me storage shortcut in the public folder stopped working, i tried other alternatives but this worked for me

MrPunyapal's avatar

@usman what if we are using an s3 bucket or suddenly we need to switch to an s3 bucket? asset() helper will fail there right.

gustav1105's avatar

A a note, to make the above work, You must change the $imagePath from a path to a filename, I used basics to get it done like so

    //store image coverphoto and write path to database
    if ($request->file('image')->isValid()){


    $imagePath = $request->file('image')->store('public');
    $image = Image::make(Storage::get($imagePath))->resize(320,240)->encode();
    Storage::put($imagePath,$image);

    $imagePath = explode('/',$imagePath);

    $imagePath = $imagePath[1];
    
    $myTheory->image = $imagePath;

    }

    $myTheory->save();
1 like
milest's avatar

Hi Usman / gustavios / whoever looks at this ...

I have 8 hours in this, and have tried a lot of approaches. None have returned the image.

I have run storage:link and verified that Storage::get fetches the image in Tinker.

I am likely missing something really obvious,

(A) When I tried the asset() approach I received a correct and fully qualified path in my browser's "view Source", but no image displayed.

(B) So I thought I would try the Storage facade, and put use Illuminate\Support\Facades\Storage; at the head of my PortFoliosController.php

When I call the following in the @section ('contents') of index.blade.php

  <img data-src= "{{Storage::get('public/images/', $portfolio->picture) }}" alt="Card image cap">

These two errors are returned:

1/2 ErrorException in Local.php line 215: file_get_contents(C:\wamp\www\eastport\storage\app\public/images): failed to open stream: Permission denied

2/2 ErrorException in Local.php line 215: file_get_contents(C:\wamp\www\eastport\storage\app\public/images): failed to open stream: Permission denied (View: C:\wamp\www\eastport\resources\views\albums\index.blade.php)

(I tried reversing the "public/images" slash, but it made no difference.)

(C) So tried adding

    'images' => [
        'driver' => 'local',
        'root' => storage_path('app/public/images/turkey'),
        'url' => env('APP_URL').'/storage/images/turkey',
        'visibility' => 'public',
    ],

to filesystems.php and using this call in index.blade.php

            <img data-src= "{{Storage::disk('images')->get( $portfolio->picture) }}" alt="Card image cap"> 

and I get the same error as above.

Guidance will be gratefully appreciated.

herrygallery's avatar

Image can be stored in public folder i.e. in root/public, or in storage/app/public. To address the later, of course we will write

<img src="storage/myfolder/myimage.png" style="width: 100%; height: 100%;">

if the file is located in storage/app/public/myfolder, and we save the file using File copy etc syntax. But if we save the file using Storage:: syntax, the file will be saved in storage/app folder which is not accessible by public. To address this in Blade, I just write this :

<img src="{{ storage_path('app/myfolder/myimage.jpg') }}" style="width: 100%; height: 100%;">

if the file is stored in storage/app/myfolder using Storage:: syntax. And of course the config.php should be configured properly. Hope the above helps. Cheers.

1 like
nadiaam's avatar

I save the image in storage/app/public/image/ and when i use asset("storage/app/public/image/$post->image") none of the above solution works! any help will be appreciate.

atanu1761's avatar

Hello @nadiaam

Try to replace the "app/public" with "storage". This worked for me.

<img src="{{ asset("storage/image/$post->image") }}" alt=""/>

1 like
merdjpatts's avatar

Hello everyone,

Kindly help me pls to show how to display image file from storage folder to the browser. I am new to Laravel and I have difficulties displaying image file. Can anyone show me step by step way to do it or if someone can show a working sourcecode.

thank you so much

Ankit Zore's avatar

As suggested by @herrygallery You can try following:

<img src="{{ storage_path('app/' . $myTheory->image)" }}/>

Make sure you have access permissions for image file stored in storage folder

Please or to participate in this conversation.