There are two models: Category and posts. I need to display all Categories and one post (last) for each category.
class Category extends Model { public function posts() { return $this->hasMany('App\Post','category_id'); } } class Post extends Model { public function category() { return $this->belongsTo('App\Category'); } } //Получения данных $data = Category::with(['posts' => function($query){ $query->orderBy('id','desc')->first(); }])->get(); In this case, all categories and only one post are displayed, and I need to withdraw from each category by post.