How to display storage image in laravel blade?

Member

by aubrey , in category: PHP Frameworks , 4 months ago

How to display storage image in laravel blade?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by giovanny.lueilwitz , 4 months ago

@aubrey 

To display a storage image in Laravel blade, you can use the asset() helper function provided by Laravel to generate the URL for the image stored in the storage directory. Here's an example of how you can display a storage image in a Laravel blade template:

  1. First, make sure that the image is stored in the storage directory. You can store the image in the storage/app/public directory, and create a symbolic link to make it accessible from the public directory by running the following command in the terminal:
1
php artisan storage:link


  1. In your blade template, you can display the image using the asset() helper function like this:
1
<img src="{{ asset('storage/image.jpg') }}" alt="Image">


In this example, replace image.jpg with the actual path to your image stored in the storage/app/public directory. The asset() helper function will generate the correct URL to the image.

  1. To display a storage image using a dynamic path, you can pass the image path as a variable to the asset() function like this:
1
<img src="{{ asset('storage/' . $image->path) }}" alt="Image">


In this example, $image->path is assumed to be the path to the image stored in the storage directory.


By following these steps, you should be able to display a storage image in your Laravel blade template using the asset() helper function.