Level 73
There is no need to use eloquent for everything. I use it for simple queries but more complex ones I use DB:select or DB:raw.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hey people, i dont know how to write this query in eloquent?
SELECT user_from_id,
SUBSTRING_INDEX(GROUP_CONCAT(seen ORDER BY seen, created_at DESC SEPARATOR ','), ',', 1) AS seen,
SUBSTRING_INDEX(GROUP_CONCAT(chat ORDER BY seen, created_at DESC SEPARATOR ','), ',', 1) AS chat,
SUBSTRING_INDEX(GROUP_CONCAT(created_at ORDER BY seen, created_at DESC SEPARATOR ','), ',', 1) AS created_at
FROM chats WHERE user_to_id=2 GROUP BY user_from_id ORDER BY created_at DESC
Please or to participate in this conversation.