Hi I have two models Category,News
, i want to retrieve categories with 3 latest news in each category, News
models have created_at column for date when it created.
Can i achieve this in laravel
Hi I have two models Category,News
, i want to retrieve categories with 3 latest news in each category, News
models have created_at column for date when it created.
Can i achieve this in laravel
try this way,
$news = Category::whereHas('news',function($query){
$query->orderBy('created_at', 'desc')->take(3);
})->get();