Laravel display Image from Storage Folder by controller



storage\app\public
1001.jpg
404.jpg
Router:
Route::get('/get-flight-image/{image_name}',[FlightController::class,'getFlightImage'])->name('flight.get-flight-image');

Controller:
public function getFlightImage($image_name) {
        $imagePath = Storage::disk('public')->get($image_name);
        return $imagePath;
    }
OR
public function getFlightImage($image_name) {
        if (Storage::disk('public')->exists($image_name)) {
            return Storage::disk('public')->get($image_name);
        }
        if (Storage::disk('public')->missing($image_name)) {
            return Storage::disk('public')->get('404.jpg');
        }
    }
inde.blade.php
<img src="{{ route('flight.get-flight-image',['image_name'=>'1001.jpg']) }}" alt="">
Share on Google Plus

About Ram Pukar

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment