Paginate an eager loading cant work. Look at this answer.
Dec 13, 2014
4
Level 2
Paginate within a pivot table
Hi,
how can I paginate data from a pivot table? I know it could work like this:
(user and blueprint have a many-to-many-relationship)
$blueprints = User::find($user->id)->blueprints()->simplePaginate(10);
But this way, it does not eagerly load the data, thus many queries are generated :/ Also, I can't specify any constraints etc. Is there a way to achieve a pagination like this:
$blueprints = User::with(['blueprints' => function($q)
{
$q->orderBy('name', 'asc');
$q->with('slots');
$q->simplePaginate(10);
}])->find($user->id)->blueprints;
?
Thank you in advance
Level 52
Please or to participate in this conversation.