我有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