@php $familyRows = collect(); foreach ($activeEmployers as $employer) { $children = $employer->children->whereNull('archived_at'); $contracts = $employer->children->flatMap->contracts; $familyRows->push([ 'employer' => $employer, 'parentName' => $employer->display_name, 'addedAt' => $employer->created_at?->format('d/m/Y') ?? '—', 'childrenNames' => $children->pluck('first_name')->filter()->join(', '), 'contractsCount' => $contracts->count(), 'activeContractsCount' => $contracts->where('status', 'active')->count(), 'draftContractsCount' => $contracts->whereIn('status', ['draft', 'to_sign'])->count(), 'canDelete' => ! $contracts->contains(fn ($contract) => $contract->status === 'active'), ]); } $sortUrl = function (string $column) use ($sort, $direction): string { $query = request()->except(['sort', 'direction', 'page']); if ($sort !== $column) { $query['sort'] = $column; $query['direction'] = 'asc'; } elseif ($direction === 'asc') { $query['sort'] = $column; $query['direction'] = 'desc'; } return request()->url().($query ? '?'.http_build_query($query) : ''); }; $sortIndicator = fn (string $column): string => $sort === $column ? ($direction === 'asc' ? '↑' : '↓') : ''; @endphp

Enfants et parents employeurs

@if ($familyRows->isNotEmpty())
@foreach ($familyRows as $row) @php $employer = $row['employer']; @endphp @endforeach
Famille{{ $sortIndicator('family') }} Enfant(s){{ $sortIndicator('children') }} Parent employeur{{ $sortIndicator('parent') }} Contrats Ajoutée le{{ $sortIndicator('added_at') }} Actions
Total{{ $sortIndicator('contracts_total') }} Actif(s){{ $sortIndicator('contracts_active') }} Projet(s){{ $sortIndicator('contracts_draft') }}
{{ $employer->family_label }} {{ $row['childrenNames'] ?: 'Aucun enfant renseigné' }} {{ $row['parentName'] }} {{ $row['contractsCount'] }} {{ $row['activeContractsCount'] }} {{ $row['draftContractsCount'] }} {{ $row['addedAt'] }}
@if ($row['canDelete'])
@csrf @method('patch')
@endif
{{ $activeEmployers->links() }}
@else
Aucun parent employeur pour le moment.

Je commence par créer un parent employeur, puis j'ajoute les enfants accueillis.

@endif @if ($archivedEmployers->isNotEmpty())

Historique archivé

{{ $archivedEmployers->count() }} parent(s) employeur(s)
@endif