How to implement BelongsToThrough Relationship in Laravel?
I have Table:
**projects_table**
id
**categories_table**
id
project_id
**properties_table**
id
category_id
Category BelongsTo Project
public function project(){
return $this->belongsTo('App\Project');
}
Property BelongsTo Category
public function category(){
return $this->belongsTo('App\Category');
}
How can we make a relationship?
Property BelongsTo Project Through Category
public function project(){
return $this->belongsToThrough('App\Project', 'App\Category');
}
EDIT QUESTION.
Because I want to do multi-tenancy on my application, and the tenancy is PORJECT. I want to separate Category and Property by Project.
CATEGORY is belongsTo PROJECT PROPERTY is belongsTo CATEGORY
so I want to make relationship between PROPERTY and PROJECT via CATEGORY. for now, I need to add: project_id
on both categories and properties tables and I think that this is not the right way.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire