How To Display Image From Public Folder In Laravel 8

Bipsmedium
2 min readMay 5, 2021
How To Display Image From Public Folder In Laravel 8

In this tutorial, we will learn how to display image from public folder in Laravel 8. It is very simple and easy. In order to access a file inside the public folder, we have to upload the file or the document first.

Read, How to Upload an Image To Public Folder in Laravel

If you do not know how to upload a file to a public folder in Laravel8 then go through the tutorial first from the above link.

If you are using the blade template then you can access the file with the help of stored file name in the database. There are two ways to access an image from the public folder in Laravel 8.

First Solution:-

{{asset('/folder name of the stored files inside public folder Laravel/'.$variable->filename}}
For example:- {{ asset('/images/products/'.$value->product_image) }}

if you store the files inside the public folder only then you can access the file as shown below

{{asset('/'.$variable->filename)}}

where $variable->filename is the filename stored in the database that is used to compare the filename inside the public folder. If both the filename matches, the file or the image will be displayed in the blade template or HTML view of the application.

Second Solution:-

{{ URL::to('/'}}/folder name of the stored files inside public folder Laravel/'.$variable->filename
For Example:- {{ URL::to('/'}}/images/$value->product_image
In this case, you can retrieve the image or file from the public folder only as shown below
{{ URL::to('/'}}/'.$variable->filename

Both the above methods will work fine. I hope this tutorial will help you to understand how to display image from public folder in Laravel 8 .

--

--

Bipsmedium

Hi, This is Biplab and I am a PHP laravel developer and other open source technologies. I am here to share my experience with the community.