@extends('layouts.app') @section('title', 'Messages') @section('subtitle', 'Your Conversations') @section('content')

Messages

Manage your conversations with buyers and sellers

Conversations

@if($chats->count() > 0)
@foreach($chats as $chat) @php $otherUser = $chat->buyer_id === auth()->id() ? $chat->seller : $chat->buyer; $unreadCount = $chat->unreadMessages()->count(); @endphp
{{ strtoupper(substr($otherUser->name, 0, 1)) }}

{{ $otherUser->name }} @if($otherUser->company_name) ({{ $otherUser->company_name }}) @endif

@if($chat->last_message_at) {{ $chat->last_message_at->diffForHumans() }} @endif

@if($chat->last_message) {{ Str::limit($chat->last_message, 50) }} @else No messages yet @endif

{{ Str::limit($chat->product->name, 25) }}
@if($unreadCount > 0)
{{ $unreadCount }} unread
@endif
@endforeach
@else

No conversations

Start a conversation from the marketplace.

@endif
@if($activeChat) @php $otherUser = $activeChat->buyer_id === auth()->id() ? $activeChat->seller : $activeChat->buyer; @endphp
{{ strtoupper(substr($otherUser->name, 0, 1)) }}

{{ $otherUser->name }} @if($otherUser->company_name) ({{ $otherUser->company_name }}) @endif

{{ auth()->user()->isBuyer() ? 'Seller' : 'Buyer' }}

About Product

{{ $activeChat->product->name }}

${{ number_format($activeChat->product->price, 2) }}

@if($messages->count() > 0)
@foreach($messages->reverse() as $message)

{{ $message->message }}

{{ $message->created_at->format('g:i A') }} @if($message->sender_id === auth()->id() && $message->is_read) @endif
@endforeach
@else

No messages yet

Start the conversation by sending a message.

@endif
@csrf
@else

Select a conversation

Choose a conversation from the list to start messaging.

@endif
@endsection