minchevz
minchevz

Reputation: 215

How to display image from Storage(Laravel 5.2)

I try to display images which are uploaded in my storage/app directory.I successfully can upload images in storage but when i try to retrieve it shows a broken image. To retrieve, my function is :

public function getUserImage($filename)
{
    $file = Storage::disk('local')->get($filename);
    return new Response($file, 200);
}

My view:

<img src="{{route('image.show',['filename'=>'123.jpg'])}}"/>

When i try to display the image , it shows status 200 (Failed to load response data) but image is not being displayed.Just a broken image is shown. I have no idea what i am missing .Could you give me any advice ? Thanks in advance

Upvotes: 2

Views: 2183

Answers (2)

Sangar82
Sangar82

Reputation: 5230

If you want send the image to view

In your controller:

public function index()
{
    // get the filename from somewhere
    $filename = getFilename();

    $file = Storage::disk('local')->get($filename);

    return View::make('your_view')
        ->with('file', $file);
}

In your view

 <img src="/path_where_is_the_file/{{$file}}" />

Hope it helps!

Upvotes: 1

Laravel User
Laravel User

Reputation: 1129

Send filename to view and Use src like this

src='/path_to_file/filename.jpg'

Upvotes: 0

Related Questions