Relation between tree table
Hi guys !
I need some advice , i have three table
Table
users
in_stocks
articles
relation between tables
- user hasMany in_stocks
- in_stock belongsTo one articles
- article hasMany in_stocks
But if i need to extract the list of article add in stock by a specific user like :
User::find(1)->inStock->articles
Wich relation can i use ????
I've never used hasManyThrough for this kind of a structure, but try this in the User model:
public function articles()
{
return $this->hasManyThrough(Article::class, InStock::class, 'article_id', 'id', 'user_id');
// or: $this->hasManyThrough(Article::class, InStock::class, 'user_id', 'id', 'article_id');
}
Please or to participate in this conversation.