@extends('backend.app') @section('title', 'Support Ticket #' . $ticket->id) @push('style') @endpush @section('content') @php // Pre-check user and company data once to avoid loops $useUserAvatar = false; $useCompanyLogo = false; $userAvatarPath = ''; $companyLogoPath = ''; $userInitial = 'U'; $companyInitial = 'C'; if ($ticket->ticket_type == 'user' && $ticket->user) { $userInitial = strtoupper(substr($ticket->user->name, 0, 1)); if ($ticket->user->avatar && !empty($ticket->user->avatar) && file_exists(public_path($ticket->user->avatar))) { $useUserAvatar = true; $userAvatarPath = asset($ticket->user->avatar); } } elseif ($ticket->company) { $companyInitial = strtoupper(substr($ticket->company->name, 0, 1)); if ($ticket->company->logo && !empty($ticket->company->logo) && file_exists(public_path($ticket->company->logo))) { $useCompanyLogo = true; $companyLogoPath = asset($ticket->company->logo); } } // Pre-load all message user data to avoid N+1 queries and loops $messageUserData = []; foreach ($ticket->messages as $msg) { if ($msg->user) { $messageUserData[$msg->id] = [ 'name' => $msg->user->name, 'initial' => strtoupper(substr($msg->user->name, 0, 1)) ]; } else { $messageUserData[$msg->id] = [ 'name' => 'Customer', 'initial' => 'C' ]; } } @endphp

Ticket Information

#{{ $ticket->id }}
{{ $ticket->subject }}
@if($ticket->ticket_type == 'user') User @else Company @endif
{{ $ticket->created_at->format('M d, Y') }}

@if($ticket->ticket_type == 'user' && $ticket->user)
@if($useUserAvatar) avatar @else {{ $userInitial }} @endif
@elseif($ticket->company)
@if($useCompanyLogo) logo @else {{ $companyInitial }} @endif
{{ $ticket->company->name }}
{{ $ticket->company->city ?? 'Service Provider' }}
@endif

Conversation History

Last Activity: {{ $ticket->last_message_at ? $ticket->last_message_at->diffForHumans() : 'N/A' }}
@forelse($ticket->messages as $message) @if($message->is_admin)
Admin A

{!! nl2br(e($message->message)) !!}

@if($message->attachment_path) @php $ext = pathinfo($message->attachment_path, PATHINFO_EXTENSION); @endphp @if(in_array(strtolower($ext), ['jpg', 'jpeg', 'png', 'gif', 'webp']))
Attachment
@else @endif @endif
{{ $message->created_at->format('M d, g:i A') }}
@else
{{ $messageUserData[$message->id]['initial'] }} {{ $messageUserData[$message->id]['name'] }}

{!! nl2br(e($message->message)) !!}

@if($message->attachment_path) @php $ext = pathinfo($message->attachment_path, PATHINFO_EXTENSION); @endphp @if(in_array(strtolower($ext), ['jpg', 'jpeg', 'png', 'gif', 'webp']))
Attachment
@else @endif @endif
{{ $message->created_at->format('M d, g:i A') }}
@endif @empty

No messages yet. Start the conversation!

@endforelse
@if(!$ticket->isClosed())
@csrf
@else
This ticket is archived

This conversation has been closed and cannot be replied to. Re-open the ticket if further assistance is required.

@endif
@if($ticket->ticket_type == 'user') Back to User Tickets @else Back to Company Tickets @endif
@endsection @push('script') @endpush