F
Filament3mo ago
Bruno

Hiding the super_admin role

Hello everyone, user creation, I have a select with the roles (super_admin, panel_user, manager_user, seller_user), I would like to hide the super_admin information from the other roles. I'm using filament shield plugin. how do I do this?
4 Replies
awcodes
awcodes3mo ago
Are you using options() or relationship() on the select?
Bruno
BrunoOP3mo ago
Options(with RolesEnum) on the select
awcodes
awcodes3mo ago
Hmm. Ok. I don’t think it’s going to be possible with an enum, since their values aren’t conditional. Why an enum instead of utilizing the package to derive them from the model? Might get more help in #bezhansalleh-shield though as it relates to the plugin too.
Dennyvik
Dennyvik3mo ago
I am able to achieved this using relationship. In my case, I also added role group on top of role from filament-shield.
Forms\Components\Select::make('roles')
->preload()
->relationship('roles', 'name',
function (Builder $query) use ($userAuth)
{
if( $userAuth->first()->group !== 'ADMIN'){
$query->where('name', '!=', 'super_admin');
}
}
)
->required()
->live()
->disabled(function() use ($userAuth){
if($userAuth->first()->group !== 'ADMIN'
&& auth()->user()->roles->first()->name !== 'founder')
{
return true;
}
})
Forms\Components\Select::make('roles')
->preload()
->relationship('roles', 'name',
function (Builder $query) use ($userAuth)
{
if( $userAuth->first()->group !== 'ADMIN'){
$query->where('name', '!=', 'super_admin');
}
}
)
->required()
->live()
->disabled(function() use ($userAuth){
if($userAuth->first()->group !== 'ADMIN'
&& auth()->user()->roles->first()->name !== 'founder')
{
return true;
}
})
Want results from more Discord servers?
Add your server