Varinder
Varinder

Reputation: 202

how to retrieve image from database in laravel 5.1?

I have image name in the database and image upload in public/image folder.

Now I want to show the image on the web page.

How do I do this?

I am using

<img src="{{ URL::to('/') }}/images/{{ $item->Photo }}" alt="{{ $item->Title }}"/>

Upvotes: 2

Views: 5121

Answers (4)

jonm
jonm

Reputation: 131

{{HTML::image("images/$item->YourDBFieldNameOfImageURL", "ALT description", "");}}

Upvotes: 0

shempignon
shempignon

Reputation: 562

You can use the asset() helper function, like so:

<img src="{{ asset("images/$item->Photo") }}" alt="{{ $item->Title }}" >

Upvotes: 2

elfif
elfif

Reputation: 1857

Easiest way would be to add a method to your user model.

That method will return the url of your image, you will name that method getImageUrl() for example.

your function :

public function getImageUrl(){
    return asset($this->image);
}

That way you just have to do something like this in your view

<img src="{{ $user->getImageUrl() }}" />

Then if at some point you change the storage location of your pictures you just have to change it in the getImageUrl function.

Upvotes: 0

Saad
Saad

Reputation: 1221

You could use <img src="{{ asset('/image') }}" />

Upvotes: 0

Related Questions