I am trying to display product on the category, and I use eager loading. how i can get it?
my table
- product => product_id | productCategory_id | etc
- category => category_id | name_category
- productImage => productImage_id | product_id | name_image
product is one to many with Category product is one to many with productImage
my product controller
$product = M_productImage::with(array('product' => function($query)
{
$query->where('productCategory_id', '!=', 6);
}))->orderBy('productImage_id','=', 'desc')->groupBy('product_id')->take(4)->get();
my view
<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>
I'm traying using dd($product) there is value in it and true, but i don't know what's wrong with my view, the view result is Trying to get property of non-object