$user->load(["relation" => function ($qco) use ($max){
return $qco->select(...)
->orderBy('created_at', 'desc')
->with(["child" => function ($qtg) {
return $qtg->select(...))
->latest()->take(3);
}])->take($max);
the above generate below sql query:
[{"query":"select * from `relation` where `relation`.`user_id` in (2)) and `relation`.`deleted_at` is null order by `created_at` desc limit 5","bindings":[],"time":10.4},
{"query":"select * `child` where `child`.`foreign_key` in (2307, 2308, 2312, 2324, 2325) and `child`.`deleted_at` is null order by `created_at` desc limit 3","bindings":[],"time":3.22}]
so it's quite obvious the child is sum of total 3 including all relation (2307, 2308, 2312, 2324, 2325) under user.
This is in laravel 8.12. I noticed the above is giving expected result in Laravel 11.
Also mind this link: https://laracasts.com/discuss/channels/eloquent/query-with-relationship-and-limit
you have the reason and answer.