簡體   English   中英

如何使用Laravel中的刀片從數據庫檢索圖像並將其顯示在視圖上

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

我正在使用

php artisan storage:將圖像存儲到數據庫的鏈接。 符合預期,圖像存儲在數據庫中。 但是我在檢索圖像並將其顯示在視圖上時遇到了問題。我嘗試了其他類型的方法,但沒有用。 這是我獲取記錄的代碼。

 public function show($id) { $Attendees=Attendee::where('event_id',$id)->OrderBy('first_name','ASC')->get(); return view('Attendee',['Attendees'=>$Attendees,'id'=>$id]); } 
這是我的代碼,用於在視圖上顯示數據。

 <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> 
有人可以幫我嗎???

如果您確定圖像已存儲到數據庫中。 因此您必須檢索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