我有2个表,客户和公司 每个公司都有许多客户,每个客户都有一个公司Laravel雄辩的问题:方法不存在
这是我的模型:
class Client extends Model
{
public function company(){
return $this->hasOne('App\Company');
}
}
class Company extends Model
{
public function clients(){
return $this->hasMany('App\Client');
}
}
我试图让公司 的所有客户端的列表,这就是我试图做的:
$clients = Company::where('guid',$guid)->clients()->all();
我得到这个错误:
BadMethodCallException in Macroable.php line 74:
Method clients does not exist.
感谢您的帮助!
'where'只会创建一个查询。 ('guid',$ guid) - > first() - > clients() - > all()' – apokryfos
现在我得到这个错误:调用未定义的方法Illuminate \ Database \ Query \ Builder :: all() –
也许:'Company :: where('guid',$ guid) - > first() - > clients() - > get()'? – apokryfos