@php $prevDate = null; @endphp
@forelse($messages as $msg)
@php
$msgDate = $msg->created_at->format('Y-m-d');
$isOut = $msg->direction === 'outgoing';
$today = now()->format('Y-m-d');
$yesterday = now()->subDay()->format('Y-m-d');
$dateLabel = $msgDate === $today ? 'Today'
: ($msgDate === $yesterday ? 'Yesterday'
: $msg->created_at->format('d M Y'));
@endphp
@if($msgDate !== $prevDate)
{{ $dateLabel }}
@php $prevDate = $msgDate; @endphp
@endif
@empty
@endforelse