$userId = auth()->id(); //recupero l'id dell'utente
$userRoles = auth()->user()->roles->pluck('name'); //recupero i ruoli dell'utente
return $table
->modifyQueryUsing(
fn (Builder $query) => $query->where(function ($query) use ($userId, $userRoles) {
$query->where('user_id', $userId) // if the user is the author of the request WORKS
->orWhereHas('project.responsible', function ($query) use ($userId) {
$query->where('user_id', $userId); // if the user is the project responsible WORKS
})->orWhereIn('Super Admin', $userRoles); // if the user is a super admin DOESN'T WORKS
})
)
$userId = auth()->id(); //recupero l'id dell'utente
$userRoles = auth()->user()->roles->pluck('name'); //recupero i ruoli dell'utente
return $table
->modifyQueryUsing(
fn (Builder $query) => $query->where(function ($query) use ($userId, $userRoles) {
$query->where('user_id', $userId) // if the user is the author of the request WORKS
->orWhereHas('project.responsible', function ($query) use ($userId) {
$query->where('user_id', $userId); // if the user is the project responsible WORKS
})->orWhereIn('Super Admin', $userRoles); // if the user is a super admin DOESN'T WORKS
})
)