How to display image on view page in laravel?

method 1:

If you want to display image on your blade file than you can use asset function

File name : view.php

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


<img src="{{ asset('assets/images/mahi.jpg') }}" alt="" title="">

Method 2:

we have to create route for display image

File name : route.php

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

File name : controller.php

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;

}






Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here


Ittutorial