table filters are not working when i customized getEloquentQuery()
public static function getEloquentQuery(): Builder
{
// Apply custom authorization and query modifications
if (!auth()->user()->can("viewAny")) {
$subordinateIds = auth()->user()->subordinates()->pluck('id');
// Ensure the query context is for MyEvent model
$createdByUserOrSubordinates = function ($query) use ($subordinateIds) {
$query->whereIn('creator_id', [...$subordinateIds, auth()->id()]);
};
// Ensure the query context is for MyEvent model
$eventHasAuthUserOrSubordinates = function ($query) use ($subordinateIds) {
$query->whereIn('worker_id', [...$subordinateIds, auth()->id()]);
};
// Apply conditions to the query
return parent::getEloquentQuery()->where($createdByUserOrSubordinates)
->orWhereHas('eventWorkers', $eventHasAuthUserOrSubordinates);
}
return parent::getEloquentQuery();
}
0 Replies