$receivedmessages = DB::table('messages')
->join('users', 'users.id', '=', 'messages.sender_id')
->select('messages.*', 'users.username')
->whereRaw('messages.id IN (SELECT MAX(messages.id) FROM messages GROUP BY receiver_id, sender_id)')
->where('receiver_id', Auth::user()->id)
->orderByDesc('messages.created_at')
->get();