You should be able to put it in your closure:
['category.articles' => function ($query) {
$query->where('language', 'en')
->with('editor', 'poster');
}],
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
i'm trying to get editor and poster data for every article in single query, unfortunately i'm not getting these data on the final query.
this is my code
public function widgets($id = null)
{
if($id){
$pageID = $id;
}else{
$id = 1;
}
$widgets = Widget::with(
['category.articles' => function ($query) {
$query->where('language', 'en');
}],
'category.articles.editor',
'category.articles.poster',
'buttons', 'content', 'content.linkedPage', 'content.linkedArticle'
)
->where('page_id', '=', $id)
->orderBy('sorting', 'asc')
->get();
return $widgets;
}
After running the code i'm not returning the editors neither the poster data.
is there is a better way on how to this type of query.
any ideas ???
You should be able to put it in your closure:
['category.articles' => function ($query) {
$query->where('language', 'en')
->with('editor', 'poster');
}],
Please or to participate in this conversation.