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
What was wrong with JarekTkaczyk's method?
I found the solution with JarekTkaczyk's tweak.
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
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community