@php // Global null-safe initialization to prevent "Undefined variable $existingCustomers" in compiled views $authUser = \Auth::user(); $isCustomerContext = false; // logged-in user is a customer $isAgentContext = false; // logged-in user is an agent $customerUserId = null; // store id if customer $agentUserId = null; // store id if agent try { if($authUser){ // Examine attached roles without modifying existing logic $roleSlugs = $authUser->roles()->pluck('slug')->map(fn($s)=> strtolower($s))->all(); if(in_array('customer',$roleSlugs,true)) { $isCustomerContext = true; $customerUserId = $authUser->id; } if(in_array('agent',$roleSlugs,true)) { $isAgentContext = true; $agentUserId = $authUser->id; } } } catch (\Throwable $e) { /* fail-safe: leave flags false */ } // Provide small JS-exposed flags (no logic change, purely for conditional UI hide) $ctxFlags = [ 'isCustomerContext' => $isCustomerContext, 'isAgentContext' => $isAgentContext, 'customerUserId' => $customerUserId, 'agentUserId' => $agentUserId, ]; if(!isset($existingCustomers)){ $existingCustomers = collect(); if(isset($schedule)){ try { if($schedule->relationLoaded('scheduleCustomers')){ $existingCustomers = $schedule->scheduleCustomers->load('customer'); } else { $existingCustomers = $schedule->scheduleCustomers()->with('customer')->get(); } } catch (\Throwable $e) { $existingCustomers = collect(); // fail safe } } } @endphp

Customers

@if($tenantSettingsVal == 1) @endif
@php // Null-safe eager customer collection (controller did not pass $existingCustomers) $existingCustomers = collect(); if(isset($schedule)){ // If relation already loaded we avoid extra query; else lazy load with customer if($schedule->relationLoaded('scheduleCustomers')){ $existingCustomers = $schedule->scheduleCustomers->load('customer'); } else { $existingCustomers = $schedule->scheduleCustomers()->with('customer')->get(); } } @endphp @php // When customer context: filter collection to only logged-in customer (if present) if($isCustomerContext && $customerUserId){ $existingCustomers = $existingCustomers->filter(function($row) use ($customerUserId){ return (int)$row->customer_id === (int)$customerUserId; }); } @endphp @forelse($existingCustomers as $row) @php $cust = $row->customer; @endphp @if($cust) @endif @empty @if($isCustomerContext && $authUser) @else @endif @endforelse
Customer Name Customer Type Agreement Signee Permissions Email Phone/Mobile Action

{{ $cust->first_name }} {{ $cust->last_name }}

{{ $cust->email }} @php $phone = \App\Helpers\Helper::formatPhone($cust->phone ?? ''); $mobile = \App\Helpers\Helper::formatPhone($cust->mobile ?? ''); $phoneDisplay = []; if ($phone) $phoneDisplay[] = "P: " . $phone; if ($mobile) $phoneDisplay[] = "M: " . $mobile; @endphp {{ implode(' | ', $phoneDisplay) ?: 'N/A' }} @unless($isCustomerContext) @endunless

{{ $authUser->first_name }} {{ $authUser->last_name }}

{{ $authUser->email }} @php $phone = \App\Helpers\Helper::formatPhone($authUser->phone ?? ''); $mobile = \App\Helpers\Helper::formatPhone($authUser->mobile ?? ''); $phoneDisplay = []; if ($phone) $phoneDisplay[] = "P: " . $phone; if ($mobile) $phoneDisplay[] = "M: " . $mobile; @endphp {{ implode(' | ', $phoneDisplay) ?: 'N/A' }}
There are no customers.

Agents

@if ($tenantSettingsVal == 1) @endif
@php $existingAgents = $schedule->scheduleAgents()->with('agent')->get(); if($isAgentContext && $agentUserId){ $existingAgents = $existingAgents->filter(function($row) use ($agentUserId){ return (int)$row->agent_id === (int)$agentUserId; }); } @endphp @forelse($existingAgents as $row) @php $ag = $row->agent; @endphp @if($ag) @endif @empty @if($isAgentContext && $authUser) @else @endif @endforelse
Agent Name Agent Type Email Phone/Mobile Notes Action

{{ $ag->first_name }} {{ $ag->last_name }}

{{ $ag->email }} @php $phone = \App\Helpers\Helper::formatPhone($ag->phone ?? ''); $mobile = \App\Helpers\Helper::formatPhone($ag->mobile ?? ''); $phoneDisplay = []; if ($phone) $phoneDisplay[] = "P: " . $phone; if ($mobile) $phoneDisplay[] = "M: " . $mobile; @endphp {{ implode(' | ', $phoneDisplay) ?: 'N/A' }} {{ Str::limit($ag->note,50) }} @unless($isAgentContext)
@endunless

{{ $authUser->first_name }} {{ $authUser->last_name }}

{{ $authUser->email }} @php $phone = \App\Helpers\Helper::formatPhone($authUser->phone ?? ''); $mobile = \App\Helpers\Helper::formatPhone($authUser->mobile ?? ''); $phoneDisplay = []; if ($phone) $phoneDisplay[] = "P: " . $phone; if ($mobile) $phoneDisplay[] = "M: " . $mobile; @endphp {{ implode(' | ', $phoneDisplay) ?: 'N/A' }} {{ Str::limit($authUser->note,50) }}
There are no agents.
@php $placeApiKey = \Config::get('settings.address_auto_populate_key'); @endphp