Assuming you have an Eloquent model name ChatMessage, this should work:
$message = ChatMessage::latest()->where('sender_id', 1)->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Sorry that I have to ask such a noobie question, but I learned SQL about 8 years ago and never used anymore.
It should be quite simple, if you look at this current database: https://imgur.com/a/hSF1M
So my goal is to get from that for example with sender_id = 1
id sender_id receiver_id content read created_at
3 1 2 Freut mich 0 2018-01-15 20:09:19
5 1 4 Hey Jake 0 2018-01-16 18:09:19 (sorry had a timestamp mistake)
So I know the sender_id, but I want I just need the latest created_at message with it's content.
My first approach was old school SQL but I stuck:
SELECT DISTINCT sender_id, receiver_id FROM chats Where sender_id = 1
I hope it's understandable what I want. Thank YOU for your help.
Please or to participate in this conversation.