我正在尝试在该类别上显示产品,并使用预先加载。我怎么能得到它?
我的桌子
产品是一对多的类别 产品是一对多的productImage
我的产品控制器
$product = M_productImage::with(array('product' => function($query)
{
$query->where('productCategory_id', '!=', 6);
}))->orderBy('productImage_id','=', 'desc')->groupBy('product_id')->take(4)->get();
我的观点
<ul class="row list-unstyled" style="min-height: 442px;">
@foreach($product as $value)
<li class="col-xs-12 col-sm-6 col-md-3 col-lg-3 text-center animated">
<div class="product">
<figure class="figure-hover-overlay">
<a href="#" class="figure-href"></a>
@if($value->product->status_product == 2)
<div class="product-new" style="width:100px !important;">Limited Stock</div>
@elseif($value->product->status_product == 3)
<div class="product-sale" style="width:100px !important;">Sold out</div>
@endif
<img width="400px" height="450px" class="img-responsive" src="{{ asset('assets/image/product/medium/'.$value->productImage_name)}}" alt="" title="">
<span class="bar"></span>
<figcaption>
<a href="#" title="Wishlist"><i class="icon-heart"></i></a>
<a href="#" class="shoping"><i class="glyphicon glyphicon-shopping-cart"></i></a>
<a href="#" title="Compare"><i class="glyphicon glyphicon-sort"></i></a>
</figcaption>
</figure>
<div class="product-caption" >
<p style="height:50px;"><a href="{{ URL::to('productdetail/'. $value->product->product_id ) }}" class="product-name">{{$value->product->title_product}}</a></p>
<p class="product-price"><span>{{$value->product->priceBefore}}</span> {{$value->product->priceAfter}}</p>
</div>
</div>
</li>
@endforeach
</ul>
我正在使用dd($ product)进行交易,其中有值且是真的,但我不知道我的视图有什么问题,视图结果是试图获取非对象的属性
答案 0 :(得分:0)
使用 whereHas
进行解决 $id = 7;
$product = M_productImage::whereHas('product', function($q) use ($id)
{
$q->where('productCategory_id','!=', $id);
})->orderBy('productImage_id','=', 'desc')->groupBy('product_id')->take(4)->get();
显示在my pastebin
中