简体   繁体   中英

How to retrieve image from database and display it on view using blade in laravel

I'm using

php artisan storage:link to store the images to database. As expected Images are storing in database. But I've problem in retrieving the images and displaying them on the view.I tried different type of methods but not working. This is my code to get the records.

 public function show($id) { $Attendees=Attendee::where('event_id',$id)->OrderBy('first_name','ASC')->get(); return view('Attendee',['Attendees'=>$Attendees,'id'=>$id]); } 
This is my code to display data on view.

 <div class="col-sm-10" style="margin:0px 0px 0px 225px"> <a href="{{url('attendeeAdd',[$id])}}" style="float:right">Add Attendee</a> @foreach($Attendees as $deligate) <img src="{{ asset('images/$deligate->id') }}"> <h4><span>{{$deligate->first_name}}</span> <span>{{$deligate->last_name}}</span></h4> @endforeach </div> 
can anyone help me on this please???

If you sure that your image is stored into the Database. so you have to retrieve the BLOB data.

$blob = $deligate->image_field; // image field name of Table
{{'<img src="data:image/jpeg;base64,'.base64_encode( $blob ).'"/>' }}

在花了很多时间之后,我得到了答案。

 <img src="{{ URL::asset('storage/images'.$deligate->profile_image) }}"> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM