Answer the question
In order to leave comments, you need to log in
How to get N news of each category in laravel using eloquent builder?
There is an array of id categories [1,2,3]. You need to choose 5 news from each category. But this is clearly the wrong solution...
return Category::whereIn('id', [1,2,3])
->with(
['articles' => function ($query) {
$query->latest('published_at');
$query->take(5);
}
]
)->get();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question