wie man benutzt, wobei in Laravel

//https://laravel.com/docs/9.x/queries#conditional-clauses

$result = $query
    ->where('precedence', '=', $precedenceStatus)
    ->when($person, function ($query) use ($person) {
        $query->whereHas('personnel', fn ($q) => $q->where('id', '=', $person));
    })
    ->get();
SAMER SAEID