Answer the question
In order to leave comments, you need to log in
Is it possible to connect a second model in addition to the "relationships"?
return $this->hasManyThrough(
'App\Owner',
'App\Car',
'mechanic_id', // Foreign key on cars table...
'car_id', // Foreign key on owners table...
'id', // Local key on mechanics table...
'id' // Local key on cars table...
);
Answer the question
In order to leave comments, you need to log in
If intermediate models are also needed, then it is better to use not hasManyThrough as in your example, but hasMany/belongsTo.
Those. of the original model you prescribe the connection
public function owner(){
return $this->belongsTo('App\Owner');
}
public function cars(){
return $this->hasMany('App\Car');
}
Model::with('owner.cars')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question