@extends('admin.layout') @section('content')

Comienza un nuevo chat

@csrf

Tus Chats

@foreach($chats as $chat) @php // Determine the correct recipient name $recipient = ($chat->user_id === auth()->id()) ? $chat->recipient : $chat->user; $lastMessage = $chat->messages->first(); // Get the last message (already fetched in the query) // Determine if the last message is from the logged-in user or the recipient $lastMessageSender = $lastMessage && $lastMessage->user_id === auth()->id() ? 'TĂș' : $recipient->name; @endphp @if($lastMessage)
Chat con {{ $recipient->name }}

{{ $lastMessageSender }}: {{ $lastMessage->body }} {{ $lastMessage->created_at->format('d M Y, H:i') }}

@endif @endforeach
@endsection @push('js') {{-- --}} @endpush