@php
$previousSenderId = null;
@endphp
@foreach($messages->reverse() as $message)
@if($message->sender_id !== $previousSenderId)
@if($message->sender_id != auth()->id())
@if($message->sender->image)
@else
{{ strtoupper(substr($message->sender->name, 0, 1)) }}
@endif
@endif
@if($message->sender_id != auth()->id())
{{ $message->sender->name }}
@else
You
@endif
@php
$time = $message->created_at->diffForHumans(null, true);
$shorthand = str_replace(
[' seconds', ' minutes', ' hours', ' days', ' weeks', ' months', ' years'],
['s', 'm', 'h', 'd', 'w', 'mo', 'y'],
$time
);
@endphp
{{ $shorthand }}
@if($message->sender_id == auth()->id())
@if(auth()->user()->image)
@else
{{ strtoupper(substr(auth()->user()->name, 0, 1)) }}
@endif
@endif
@endif
{{ $message->message }}
@php
$previousSenderId = $message->sender_id;
@endphp
@if($loop->last || $messages[$loop->index + 1]->sender_id !== $message->sender_id)
@endif
@endforeach