How to display image from storage folder in Laravel?

How to display image from storage folder in Laravel?

In this post we will give you information about How to display image from storage folder in Laravel?. Hear we will give you detail about How to display image from storage folder in Laravel?And how to use it also give you demo for it if it is necessary.

In this example, i will give you example of laravel display image from storage folder. we can easily show image from storage folder in laravel 6 application. we will display image from storage folder in blade file of laravel 6 project.

All most developer and client want to store images or files secure on his server. so anyone can not access directly using url. that’s the reason laravel introduce storage folder file upload. Almost using storage folder for uploading files and images on his laravel app. But when you upload it also might be require to display or download for that image or file.

However, In this example, i will give you 2 way to show your image in blade file.

Solution 1:

first of all if you want to show image using asset function than you need to link your storage folder using following command:

php artisan storage:link

Now you can write image upload logic on your controller and image upload.

If you want to display image on your blade file than you can use asset function as like bellow example:

<img src="{{ asset(.'/images/'.$article->image) }}" alt="" title="">

Solution 2:

In second solution, we have to create route for display image on your application. so let’s create route as like bellow:

Create Route:

Route::get('image/{filename}', 'HomeController@displayImage')->name('image.displayImage');

Create Controller Method:

public function displayImage($filename)

{

$path = storage_public('images/' . $filename);

if (!File::exists($path)) {

abort(404);

}

$file = File::get($path);

$type = File::mimeType($path);

$response = Response::make($file, 200);

$response->header("Content-Type", $type);

return $response;

}

Now you can use like as bellow:

<img src="{{ route('image.displayImage',$article->image_name) }}" alt="" title="">

You can use anyone.

I hope it can help you…

Hope this code and post will helped you for implement How to display image from storage folder in Laravel?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  27  =  36

We accept paid advance and paid guest Posting on our Site : Contact US