Laravel 4 laravel 4.0:急切加载错误-在选择条件时尝试获取非对象的属性

Laravel 4 laravel 4.0:急切加载错误-在选择条件时尝试获取非对象的属性,laravel-4,eager-loading,Laravel 4,Eager Loading,我正在尝试在类别上显示产品,并且我使用了渴望加载。我怎样才能得到它 我的桌子 产品=> 产品标识|产品类别|标识|等 类别=> 类别|名称|类别 productImage=> 产品形象|产品形象|名称|形象 产品是一对多的类别 产品是具有productImage的一对多产品 我的产品控制器 $product = M_productImage::with(array('product' => function($query) { $q

我正在尝试在类别上显示产品,并且我使用了渴望加载。我怎样才能得到它

我的桌子

  • 产品=> 产品标识|产品类别|标识|等
  • 类别=> 类别|名称|类别
  • productImage=> 产品形象|产品形象|名称|形象
  • 产品是一对多的类别 产品是具有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>
    
      @foreach($product as$value)
    • @如果($value->product->status\u product==2) 有限股票 @elseif($value->product->status\u product==3) 售罄 @恩迪夫 productImage_name)}}“alt=”“title=”“> 高度:50px;“>

      {{{$value->product->priceBefore}{{{$value->product->priceAfter}}

    • @endforeach

    我正在使用dd($product)它有价值,但我不知道我的视图有什么问题,视图结果是尝试获取非对象的属性

    此解决方案使用Where has

        $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();
    
    展示