@php $companyKeys = [ 'company_name_en', 'company_address_en', 'tax_number', 'commercial_register', 'tourism_license', ]; $company = \App\Models\Setting::whereIn('key', $companyKeys)->pluck('value', 'key'); $isOther = ($invoice->free_invoiceable_type === 'other'); $linked = $isOther ? null : $invoice->freeInvoiceable; // Only access relation when not 'other' $displayName = $isOther ? ($invoice->beneficiary_name ?? '-') : (($linked->company_name ?? $linked->name ?? '-') ?? '-'); $displayAddress = $isOther ? ($invoice->beneficiary_address ?? '-') : ($linked->address ?? '-'); $displayTax = $isOther ? ($invoice->beneficiary_tax_number ?? '-') : ($linked->tax_number ?? '-'); $displayPhone = $isOther ? ($invoice->beneficiary_phone ?? '-') : optional(optional($linked)->contactInfos->first() ?? null)->phone; $displayEmail = $isOther ? ($invoice->beneficiary_email ?? '-') : optional(optional($linked)->contactInfos->first() ?? null)->email; @endphp

Company Details

Company Name {{ $company['company_name_en'] ?? '' }} Address {{ $company['company_address_en'] ?? '' }}
Tax Number {{ $company['tax_number'] ?? '' }} Commercial Register {{ $company['commercial_register'] ?? '' }}
Tourism License {{ $company['tourism_license'] ?? '' }}

Beneficiary Details

Name {{ $displayName }} Address {{ $displayAddress }}
Tax Number {{ $displayTax }} Phone {{ $displayPhone }}
Email {{ $displayEmail }}

Invoice Items

@php $items = (array) ($invoice->items ?? []); @endphp @forelse($items as $idx => $item) @php $qty = (float)($item['quantity'] ?? 0); $price = (float)($item['price'] ?? 0); $rowTotal = $qty * $price; @endphp @empty @endforelse
# Item Quantity Price Total
{{ $loop->iteration }} {{ $item['name'] ?? '-' }} {{ number_format($qty, 0) }} {{ number_format($price, 2) }} {{ number_format($rowTotal, 2) }}
No items
Invoice Total {{ number_format((float)$invoice->total, 2) }}

Dates

Issue Date {{ optional($invoice->issue_date)->format('Y-m-d') }} Due Date {{ optional($invoice->due_date)->format('Y-m-d') }}