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(),
            ]);
    }

}

i would perform a $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;
    }
Was this page helpful?