OctoberCMS Register users by group

323 Views Asked by At

I would like during registration the user can choose a group, and register users by to their group

for example at registration there are 2 groups, "freelancer" and "employer"

Thank you for your help

1

There are 1 best solutions below

0
On

I don't believe you can do this with the existing user plugin Account component. Mostly because it uses Auth::register() to save the new user and there is no relation saving there.

You could create your own component that extends the account component and from your own form call onRegisterPlus() function.

public function onRegisterPlus()
{
    $this->onRegister();// call the accout component onRegister method

    /** You may want to do some verification here that this
        is a new registraion to prevent submitting existing
        email and changing the groups.
        or not use $this->onRegister() and just copy it to
        your own method and modify to fit your needs.
    */

    if($user= User::where('email',post('email'))->first()){
        $user->groups()->sync(post('groups'))
    }
}

You would make your form as mentioned and include checkboxes named 'groups[]' with the value of the groups you want available.