{{-- resources/views/emails/appointments/scheduled_for_client.blade.php --}} @php /** Accept either $appt or $appointment */ /** @var \App\Models\Appointment|null $appt */ $appt = $appt ?? ($appointment ?? null); // --- Resolve a friendly greeting name robustly --- $resolveFirst = function ($appt) { try { // Prefer a loaded relation $client = null; if ($appt?->relationLoaded('client')) { $client = $appt->client; } elseif (method_exists($appt, 'client')) { $client = $appt->client()->first(); } // If still unknown, try by client_id (User first, then Client) if (!$client && isset($appt->client_id)) { if (class_exists(\App\Models\User::class)) { $client = \App\Models\User::find($appt->client_id) ?? $client; } if (!$client && class_exists(\App\Models\Client::class)) { $client = \App\Models\Client::find($appt->client_id); } } if ($client) { $fn = $client->first_name ?? null; if (is_string($fn) && trim($fn) !== '') { return trim($fn); } $nm = $client->name ?? null; if (is_string($nm) && trim($nm) !== '') { return explode(' ', trim($nm), 2)[0]; } } } catch (\Throwable $e) { // swallow: email should never fatal on greeting name } return null; }; // Friendly greeting name (explicit var -> derived -> fallback) $firstName = $firstName ?? $clientFirstName ?? $resolveFirst($appt) ?? 'there'; // Safely render description: // 1) escape HTML, // 2) auto-link URLs, // 3) preserve line breaks if (!function_exists('appt_email_autolink')) { function appt_email_autolink(string $text): string { // Make URLs clickable (http/https) $pattern = '~(https?://[^\s<]+)~i'; return preg_replace($pattern, '$1', $text); } } $rawDesc = trim((string) ($appt->description ?? '')); $descHtml = $rawDesc !== '' ? nl2br(appt_email_autolink(e($rawDesc))) : ''; // Choose start/end fields (new or legacy) $start = $appt?->scheduled_start ?? $appt?->starts_at ?? null; $end = $appt?->scheduled_end ?? $appt?->ends_at ?? null; // Formatters that accept Carbon or string $fmt = function ($v) { if ($v instanceof \Illuminate\Support\Carbon) return $v->format('M d, Y g:i A'); return \Illuminate\Support\Carbon::parse($v)->format('M d, Y g:i A'); }; $fmtTime = function ($v) { if ($v instanceof \Illuminate\Support\Carbon) return $v->format('g:i A'); return \Illuminate\Support\Carbon::parse($v)->format('g:i A'); }; @endphp
Hello {{ $firstName }}!
Your agent has scheduled an appointment:
If the button doesn’t work, copy and paste this link into your browser:
{{ route('client.appointments.confirm', ['appointment' => $appt->id]) }}
@endif