Level 27
@ch17 In what way does your activities table store multiple actions?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I have a table called activities that stores id, user_id, actions, created_at. I want to get action-count per user per day. Something like.
| Date | User ID | Action Count | | ------ | ----------- | ----------- | | 2020-03-12 | 2 | 12 | | 2020-03-12 | 3 | 15 | | 2020-03-13 | 2 | 19 | | 2020-03-13 | 3 | 10 |
Can you please suggest me how can I do that?
Thanks in advance.
$activities = DB::table('activities')
->selectRaw('user_id, date(created_at) as date, sum(actions) as actions'))
->groupByRaw('user_id, date(created_at)')
->get();
Everything what you need you find in the documentation
Please or to participate in this conversation.