Level 122
you will get the first four of the relation. not 4 of each
you need this package https://github.com/staudenmeir/eloquent-eager-limit
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
For example I have 3 types and I need to retrieve 4 productions of each type, so 12 productions at all.
$types = Type::with(['productions' => function ($query) {
$query
->where('published', true)
->orderBy('creation_date', 'desc')
->orderBy('created_at', 'desc')
->limit(4);
}])->orderBy('order')->get();
But it retrieves me only 4 productions.
Why ? I don't understand ... what's wrong in my code ?
Thanks a lot for your help ;).
Vincent
you will get the first four of the relation. not 4 of each
you need this package https://github.com/staudenmeir/eloquent-eager-limit
Please or to participate in this conversation.