I want to retrieve multiple images of single user..? anybody pls help me.
Controller:
public function fetch(){
$id = Auth::user()->id;
$ads = Ads::where('user_id', $id)->with('images')->get();
return view('home', ['ads'=> $ads]);
}
Blade View:
@foreach ($ads as $ad)
<div class="card" onclick="" style="width: 19rem; float:left; margin-left: 10px; margin-top:10px; margin-bottom:50px; ">
<div class="card-header"> {{ $ad->product_name }} </div>
<div class="card-body">
<div id="demo" class="carousel slide" data-ride="carousel" style="height: 200px;">
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- The slideshow -->
<div class="carousel-inner">
<div class="carousel-item active">
@foreach ($ads->images as $item)
<img src="{{asset('storage/app/images/'.$item->filename)}}" alt="Los Angeles">
@endforeach
@endforeach
模型中的images
功能应该使用hasMany
而不是belongsTo
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.