Laravel

Laravel – Paginate on related model

Imagine you have many galleries each one has many photos. When you visit a specific gallery, eg: /galleries/2 you want to paginate the photos that belong to the gallery.

One line of code:

public function view( Gallery $gallery ) {
   return $gallery->photos()->paginate(10);
}