My previous posts asked about the query itself but led to problematic results so I thought maybe it's possible to filter results after query and before pagination, or after pagination?
This is the problem: I need a complex query, so I have to use raw SQL which returns an array, thus I can't use paginate on it.
What I need is to display is the oldest message of a user, example data:
id user_id message date_posted
1 5 some_message 2022-07-15
2 125 some_message 2022-08-02
3 5 some_message 2022-04-05
In this example, I'll need to display only rows 2 and 3 because the user with user_id of 5 has 2 records, but I need the older one which is row 3
Since the SQL query for that made some problems for pagination. Is it possible to just fetch everything and then filter it after or before I use the ->paginate() method?
Messages::paginate(15); // then do something to only show the latest message of each user
If nothing works, I'll give LengthAwarePaginator a try to create my own paginator