I need to use the count()
method on the latest 1000 records.
Example, we have 3 users:
- User A with 900 records
- User B with 20.000 records
- User C with 10 records
Now I want to consider only the latest 1000 records for my calculation, which means User A and C will use all their records, because < 1000, but User B uses only his last 1000 records and 19k are ignored.
// This should return for User A and C, 900 and 10, but for User C 1000
$recent_activities = Activity::select('id', 'user_id', 'activity')->where('user_id', $user->id)
->latest('id')->limit(1000)->count();
// The next 3 queries should analyse the recent 1000 records for occurences of certain %like% records and count them
$result_chat_refunds = Activity::where('activity', 'like', 'Credits erstattet%')->where('user_id', $user->id)
->latest('id')->limit(1000)->count();
$result_credit_membership = Activity::where('activity', 'like', '%Membership gutgeschrieben%')->where('user_id', $user->id)
->latest('id')->limit(1000)->count();
$result_credit_credits = Activity::where('activity', 'like', '%Credits gutgeschrieben%')->where('user_id', $user->id)
->latest('id')->limit(1000)->count();
How can I achieve this?