@forelse($conversations as $conv)
@php
$other = $conv->participants->where('id', '!=', auth()->id())->first();
$lastMsg = $conv->latestMessage;
$unread = false;
$pivot = $conv->participants->where('id', auth()->id())->first()?->pivot;
if ($lastMsg && $pivot) {
$unread = !$pivot->last_read_at || $lastMsg->created_at->gt($pivot->last_read_at);
}
$childrenInfo = $other?->_children_info ?? null;
@endphp
{{ strtoupper(substr($other->name ?? '?', 0, 1)) }}{{ strtoupper(substr(explode(' ', $other->name ?? '')[1] ?? '', 0, 1)) }}
{{ $other->name ?? 'Unknown' }}
{{ $lastMsg?->created_at?->diffForHumans(short: true) ?? '' }}
{{ $other->role ?? '' }}
@if($childrenInfo)
{{ $childrenInfo }}
@endif
@if($lastMsg)
{{ $lastMsg->sender_id === auth()->id() ? 'You: ' : '' }}{{ Str::limit($lastMsg->message, 50) }}
@else
No messages yet
@endif
@if($unread)
@endif
No conversations yet
Start a new message to begin chatting