I have this data in db:
id | user_id | status
1 | 7 | sent
2 | 7 | pending
3 | 8 | pending
4 | 8 | sent
how do I make a query so that I get this result:
id | user_id | status
4 | 8 | sent
this query is not working as expected:
MyTable::where('status', 'sent')->groupBy('user_id')->get();
result:
id | user_id | status
1 | 7 | sent
4 | 8 | sent
the latest status
in db on user_id
of 7
is pending
and I don’t want to include it in the result.
please help
fyi, I’m using Laravel 9. thanks
2
Answers
solved:
you should select only the last status where it is ‘sent’
somethink like:
I did not got the change to test it.