Laravel eloquent get the latest row of related table
问题 I have two tables, books , and chapters . One book has many chapters. Book model: public function chapters() { return $this->hasMany(Chapter::class); } Chapter model: public function book() { return $this->belongsTo(Book::class); } I want to get book list with their own latest chapter using single query like this: $books = Book::with(['authors', 'categories', 'chapters' => function($q) { $q->orderBy('updated_at', 'desc')->first(); }]->get(); But it doesn't work. Chapters return an empty array