phpsa / filament-authentication

MIT License
108 stars 23 forks source link

select only one role ? #7

Closed quasiperfect closed 2 years ago

quasiperfect commented 2 years ago

hi

thanks for your work

if there any method to force the selection of only one role ? i tried to change the BelongsToManyMultiSelect to BelongsToSelect but i get a error

TypeError
PHP 8.1.2
9.11.0
Filament\Forms\Components\BelongsToSelect::getRelationship(): Return value must be of type ?Illuminate\Database\Eloquent\Relations\BelongsTo, Illuminate\Database\Eloquent\Relations\MorphToMany returned
phpsa commented 2 years ago

change:

 BelongsToManyMultiSelect::make('roles')
                            ->relationship('roles', 'name')
                             ->preload(config('filament-authentication.preload_roles'))
                             ->label(strval(__('filament-authentication::filament-authentication.field.user.roles')))

to

 BelongsToManyMultiSelect::make('roles')
                            ->relationship('roles', 'name')
                             ->preload(config('filament-authentication.preload_roles'))
                             ->label(strval(__('filament-authentication::filament-authentication.field.user.roles')))
                             ->maxItems(1)
abhitheawesomecoder commented 1 year ago

Can I customize the message "Only 1 can be selected" ?