Level 80
@byvlad Use the whereHas() method:
$articles = Article::whereHas('tags', function ($tag) {
$tag->where('name', '=', 'foo');
})->get();
Documentation: https://laravel.com/docs/master/eloquent-relationships
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have three tables: articles tags article_tags
article_tags is a pivot table, which connect article_id and tag_id.
So i need to retrieve articles which contains specific tag. How i can do it? Thank you.
@byvlad Use the whereHas() method:
$articles = Article::whereHas('tags', function ($tag) {
$tag->where('name', '=', 'foo');
})->get();
Documentation: https://laravel.com/docs/master/eloquent-relationships
Please or to participate in this conversation.