© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
93 replies
ocram82

Assign role after registration

hi all,
It's possibile to assign role after the registration?

i've a custom register:

class Register extends BaseRegister
{
    public function form(Form $form): Form
    {
        return $form
            ->schema([
                TextInput::make('company_name')
                    ->label('Company Name')
                    ->required()
                    ->maxLength(255),
                $this->getEmailFormComponent(),
                $this->getPasswordFormComponent(),
                $this->getPasswordConfirmationFormComponent(),
            ]);
    }

}
class Register extends BaseRegister
{
    public function form(Form $form): Form
    {
        return $form
            ->schema([
                TextInput::make('company_name')
                    ->label('Company Name')
                    ->required()
                    ->maxLength(255),
                $this->getEmailFormComponent(),
                $this->getPasswordFormComponent(),
                $this->getPasswordConfirmationFormComponent(),
            ]);
    }

}

i would perform a
$user->assignRole('agency');
$user->assignRole('agency');


how can i do that?

thanks
Solution
@ocram82 I just tried it myself, this worked for me

class CustomRegister extends Register
{
    protected function handleRegistration(array $data): Model
    {
        $user = $this->getUserModel()::create($data);
        $user->assignRole('User');

        return $user;
    }
class CustomRegister extends Register
{
    protected function handleRegistration(array $data): Model
    {
        $user = $this->getUserModel()::create($data);
        $user->assignRole('User');

        return $user;
    }
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

Auto assign role
FilamentFFilament / ❓┊help
3y ago
Assign Role on Import Action
FilamentFFilament / ❓┊help
13mo ago
Redirect after registration
FilamentFFilament / ❓┊help
2y ago
Forbidden after registration
FilamentFFilament / ❓┊help
2y ago