Thursday, April 13, 2017

Laravel eloquent issue: Method does not exist

I have 2 tables, Clients and Companies each Company has many clients and each client has one company

this is my models:

class Client extends Model
{
    public function company(){
        return $this->hasOne('App\Company');
    }
}

class Company extends Model
{
    public function clients(){
        return $this->hasMany('App\Client');
    }
}

I'm trying to get a list of all the clients of a company and this is what I tried to do:

$clients = Company::where('guid',$guid)->clients()->all();

I'm getting this error:

BadMethodCallException in Macroable.php line 74:
Method clients does not exist.

thank you for your help!



via Ilan Finkel

Advertisement