Support the ongoing development of Laravel.io →
Database Eloquent Installation
Last updated 1 year ago.
0

If the activity table has created_at fields, you should do order_by

$result = Client::with(['activity' => function ($query) {
     $query->orderBy('created_at', 'desc')->limit(10);
}])->get();

Not sure if it works, didn't tested

0

@PalTamasWBA This brings only the first 10 activities for the first client.

Not for Each client

0

What was wrong with JarekTkaczyk's method?

http://laravel.io/bin/QNo9m

0

I found the solution with JarekTkaczyk's tweak.

http://laravel.io/bin/QNo9m

I tried it before but I haven't extended my "Comments" model to "BaseModel", I extended only the "Post" model.

Now , I converted it to a Trait and it's working like a charm

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

zezont4 zezont4 Joined 7 Oct 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.