简体   繁体   English

如何使用Laravel中的刀片从数据库检索图像并将其显示在视图上

[英]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. php artisan storage:将图像存储到数据库的链接。 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数据。

$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) }}"> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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