Closed swapnilsarwe closed 3 months ago
Hi @swapnilsarwe, You need to add the pivot table: https://github.com/staudenmeir/eloquent-has-many-deep?tab=readme-ov-file#manytomany
class User extends Model
{
public function categories(): HasManyDeep
{
return $this->hasManyDeep(Category::class, [Post::class, 'category_post']);
}
}
Thanks @staudenmeir . My bad, went through the example but was doing the other way round and never got it working. Appreciate your help.
I have 3 models named
User -> hasMany -> Post Post -> belongsToMany -> Category Category -> belongsToMany -> Post
Relationship are as follows
I am looking for the way where I can get all the categories for the user in the following way
Its not supported out of the box in the laravel
I tried the following & it did not work as expected. I was wondering if I am missing something.
Can anyone help me with this? If you feel this irrelevant, you can close the issue immediately.