Answer the question
In order to leave comments, you need to log in
Laravel hasOneThrough or belongsToMany. How to join three tables?
I'm trying to connect three tables, through intermediate ones.
There are such tables:
Apartments - id - number
House - id - number
House_has_aparments - id - house_id - apartment_id
Street - id - name
Street_has_houses - id - street_id - house_id
public function house()
{
return $this->belongsToMany(
Houses::class,
'houses_has_apartment',
'apartment_id',
'house_id',
'id',
'id'
);
}
public function street(){
return $this->hasOne(Streets::class);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question