Filtering table, second filter doesn't works
the first filter shows only the requests created by me
the second filter should display only the requests for which i'm responsible trough a project (a request belongTo a project, a project has many responsibles (user) )
in the request model (rams)
1 Reply
commenting this part in the table
solve the filtering problem
but i need that user can view only their request and requests for which are responsible
without this code i see all the requests from all the users
solved by adding this
public static function getEloquentQuery(): Builder
{
$userId = Auth::id(); return parent::getEloquentQuery()->when(auth()->user()->hasAnyRole(['super_admin', 'rga', 'supervisor']) === false, function ($query) use ($userId) { $query->where(function ($query) use ($userId) { $query->where('user_id', $userId) // Se l'utente è l'autore della richiesta ->orWhereHas('project.responsible', function ($query) use ($userId) { $query->where('user_id', $userId); // Se l'utente è responsabile del progetto }); }); }); }
$userId = Auth::id(); return parent::getEloquentQuery()->when(auth()->user()->hasAnyRole(['super_admin', 'rga', 'supervisor']) === false, function ($query) use ($userId) { $query->where(function ($query) use ($userId) { $query->where('user_id', $userId) // Se l'utente è l'autore della richiesta ->orWhereHas('project.responsible', function ($query) use ($userId) { $query->where('user_id', $userId); // Se l'utente è responsabile del progetto }); }); }); }