2013-12-10 52 views
4

我得到这个错误msg当我试图从我的模型中调用一个函数时,调用一个非对象的成员函数addEagerConstraints()。 下面是函数:调用成员函数addEagerConstraints()在非对象上

public static function checkClaimById($claim_id) { 
    $result = Claim::with('orders') 
     ->find($claim_id) 
     ->where('orders.user_id', Auth::user()->id) 
     ->whereNull('deleted_at') 
     ->count(); 
    if($result >= 1) { 
     return true; 
    } else { 
     return false; 
    } 
} 

我有模型“权利要求”与具有场的order_id和它属于的订单。 而且我有模型“订单”和一个订单有很多要求。

有人可以帮助我吗?

感谢 问候

回答

2

我已经修改了我的功能是这样的:

public static function checkClaimById($claim_id) { 
    $result = Claim::with(array('orders' => function($query) 
    { 
     $query->where('user_id', Auth::user()->id); 
    })) 
    ->where('id', $claim_id) 
    ->whereNull('deleted_at') 
    ->count(); 

    if($result >= 1) { 
     return true; 
    } else { 
     return false; 
    } 
} 

发现这里的解决方案:http://laravel.com/docs/eloquent#eager-loading

相关问题