I'm working on a basic messaging functionnality in Laravel and want to display each user who sent a message to the current logged in user along with the last received message, the problem is that the "orderByDesc" isn't working as it displays the first message instead of the last one.
Here's the query I wrote:
$receivedmessages = DB::table('messages')
->join('users', 'users.id', '=', 'messages.sender_id')
->select('messages.*', 'users.username')
->where('receiver_id', Auth::user()->id)
->orderByDesc('messages.created_at')
->groupBy('receiver_id')
->get();
Any idea how I can fix that? Thanks