The structure of the table in the database is as follows:
| id | body | user_id | group_id |
|---|---|---|---|
| 1 | test1 | 1 | 1 |
| 2 | test1 | 2 | 1 |
| 3 | test1 | 3 | 1 |
| 3 | test2 | 4 | 2 |
| 4 | test3 | 5 | 3 |
I want to get the first row from each group_id with Eloquent/DB Facade or MongoDB Query in Laravel with paginate:
For Example:
| id | body | user_id | group_id |
|---|---|---|---|
| 1 | test1 | 1 | 1 |
| 3 | test2 | 4 | 2 |
| 4 | test3 | 5 | 3 |
How is this achievable?
for Mongodb use this aggregation