If doing all like a report see http://dsmithweb.com/itemized.png then read http://laravel.io/forum/04-04-2015-looping-through-collection another good read http://laravel.io/forum/05-12-2015-has-many-through-relationship-depth
Child Relationship Pagination
I have my models set up and am able to return parent/child relationships between two tables; quotes and authors. I am wanting to query the authors table and return the paginated results of any related quotes associated with each author for use in a view. In my current situation, I am returning one author and their related quotes but I cannot seem to get a handle on the pagination. When I run the following code, I get no error and the results are as they seem they should be but without pagination. How do I paginate these child rows?
$author = Author::with(['quotes' => function ($q)
{
$q->where('active', '=', 1)
->paginate(15);
}])
->where('active', '=', 1)
->whereRaw('authors.slug = ?', array($id))
->limit(1)
->get();
I just thought of the way I would solve your problem, that is if you are trying to get all authers with articles.
Put the author at the top of the page with one query, right below this paginate the articles, have a custom header which has the author in it and maintain that Arthur until you go to the next Arthur, something like that where the auther is repeated at the top as necessary, in a case like this a separate query may be easier to write. If you look at the videos that Jeffrey has done at runtime a one-to-many is converted into two queries anyway.
Please or to participate in this conversation.