How to override list resource table query?

Hi I just want to override default table query to add couple of where conditions depending on a role who is on a page.
1 Reply
CerealKiller
CerealKillerOP10mo ago
This is the code I'm trying to implement:
$user = auth()->user();

$t = parent::table($table);

$t->modifyQueryUsing(function (Builder $q) use ($user) {
return match ($user->roles->first->name) {
Role::SuperAdmin->value, Role::CompanyManager->value => $q->orderBy('time', 'ASC')
->whereNull('super_admin_confirmed_at'),
Role::Admin->value => $q->orderBy('time', 'ASC'),
Role::Driver->value => $q
->where('status', '<>', DriveStatus::Canceled->value)
->where('user_id', '=', $user->id)
->whereNull('confirmed_at')
->orderBy('time', 'ASC'),
default => $q,
};
});

return $t;
$user = auth()->user();

$t = parent::table($table);

$t->modifyQueryUsing(function (Builder $q) use ($user) {
return match ($user->roles->first->name) {
Role::SuperAdmin->value, Role::CompanyManager->value => $q->orderBy('time', 'ASC')
->whereNull('super_admin_confirmed_at'),
Role::Admin->value => $q->orderBy('time', 'ASC'),
Role::Driver->value => $q
->where('status', '<>', DriveStatus::Canceled->value)
->where('user_id', '=', $user->id)
->whereNull('confirmed_at')
->orderBy('time', 'ASC'),
default => $q,
};
});

return $t;
But I am getting
Cannot use "::class" on null {"userId":1,"exception":"[object] (TypeError(code: 0): Cannot use \"::class\" on null at /var/www/html/vendor/filament/tables/src/Table/Concerns/HasRecords.php:76)
Cannot use "::class" on null {"userId":1,"exception":"[object] (TypeError(code: 0): Cannot use \"::class\" on null at /var/www/html/vendor/filament/tables/src/Table/Concerns/HasRecords.php:76)
Want results from more Discord servers?
Add your server