In this example, we will see how to get image from storage folder in laravel. You can easily get to image from storage folder in laravel.


Given below is the full example for how to get image from storage folder in laravel.




Example:

Create Route:

use App\Http\Controllers\StorageFileController;

Route::get('image/{filename}', [StorageFileController::class,'getPubliclyStorgeFile'])->name('image.displayImage');




Create Controller Method:

public function getPubliclyStorgeFile($filename)

{
    $path = storage_path('app/public/image/'. $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 it like this as given below:

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



I hope this example helps you.