I have 3 tables, first is users, post_tag, posts. The posts table has user_id
column.
I tried groupBy
in model relationship, but it doesn't work, it's still giving me duplicate result (see my code below). Someone knows how to get unique tag_id
?
Here is my User model
public function post_tags()
{
return $this->hasManyThrough(PostTag::class, Post::class)
->groupBy(['post_id','tag_id','user_id']);
}
I test it using below code, but still giving me duplicate tag_id
data.
\App\Models\User::find(11)->post_tags
I already been to these links, I did the same thing but none works for me. Laravel Grouping by Eloquent Relationship, Laravel group by, with relationship in different tables