@php
$assignedUserIds = $project->users->pluck('id')->toArray();
// Get employee user IDs
$employeeUserIds = \App\Models\Employees::whereNotNull('user_id')->pluck('user_id')->toArray();
// Get client contact user IDs for this project's client
$clientContactUserIds = [];
if ($project->client_id) {
$clientContactUserIds = \App\Models\ClientContact::where('client_id', $project->client_id)
->whereNotNull('user_id')
->pluck('user_id')
->toArray();
}
// Combine and get unique user IDs
$allowedUserIds = array_unique(array_merge($employeeUserIds, $clientContactUserIds));
// Get available users (employees + client contacts, excluding already assigned)
$availableUsers = \App\Models\User::whereIn('id', $allowedUserIds)
->whereNotIn('id', $assignedUserIds)
->orderBy('name')
->get();
// Separate into employees and client contacts for display
$employeeUsers = $availableUsers->filter(fn($u) => in_array($u->id, $employeeUserIds));
$clientContactUsers = $availableUsers->filter(fn($u) => in_array($u->id, $clientContactUserIds) && !in_array($u->id, $employeeUserIds));
@endphp
@if($employeeUsers->count() > 0)
Employees
@foreach($employeeUsers as $availableUser)
@endforeach
@endif
@if($clientContactUsers->count() > 0)
Client Team
@foreach($clientContactUsers as $availableUser)
@endforeach
@endif
@if($availableUsers->count() === 0)
All team members are already assigned to this project
@endif