Multiple select filter

How can I apply a filter to hide the admin role in the user level, except for the superadmin? I'm out of my brain. Please don't mind help me. Thank you.
Select::make('roles')
->multiple()
->relationship('roles', 'name');
Select::make('roles')
->multiple()
->relationship('roles', 'name');
7 Replies
Vp
Vp2y ago
->disabled(fn () => !auth()->user()->is_admin) or hidden
Vp
Vp2y ago
Filament
Fields - Form Builder - Filament
The elegant TALL stack form builder for Laravel artisans.
Shaung Bhone
Shaung BhoneOP2y ago
let me check w8 I don't need hidden or disable. just hide the superadmin
Vp
Vp2y ago
So in you roles select you want to load roles which doesn't contain "super_admin" right?
Shaung Bhone
Shaung BhoneOP2y ago
yes
Vp
Vp2y ago
Select::make('roles') ->relationship('roles', 'name', fn (Builder $query) => $query->where('name', '!=', 'ADMin"))
Shaung Bhone
Shaung BhoneOP2y ago
Thank you so here is my final code
->relationship('roles', 'name', function (Builder $query) use ($owner) {
if (! $owner->isOwner()) {
$query->where('name', '!=', 'super_admin');
}
})
->relationship('roles', 'name', function (Builder $query) use ($owner) {
if (! $owner->isOwner()) {
$query->where('name', '!=', 'super_admin');
}
})
Want results from more Discord servers?
Add your server