Search code examples
laravelregistration

Two different registration pages for laravel


I'm trying to create two different registration pages for laravel - one will be for "students" and another for "mentors".

There are two ways in my head I could go about routing this:

  1. Is to add in the localhost/register?user_type="mentor" and localhost/register?user_type="student". Then depending on the user_type parameter add a hidden input which will submit to laravel the user_type on registration.

  2. To add a completely second registration page localhost/register_mentor or localhost/register_student

So, I used the makeauth scaffold. But here i'm confused.

  1. I have no idea where the routes are for example:

In the "RegistrationController" I have

protected function create(array $data) 

So I know I can edit this and add a user_type column in the database.

But I have no idea where this "create" is being called? So I don't know how to put in a a new registration page that will call this with the user_type.

  1. Because I have no idea how it's being routed - I have no idea how I can copy the current register.blade.php and make a new one for a second registration page. It says in register.blade.php that the registration process is send to "{{ route('register') }" - but I have no idea where this is.

Hope I make sense, any help would be greatly appreciated!


Solution

  • The create method is being called within the register() method found in vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php. You can override the register() method found by placing it in your RegisterController.

    You also have access to the $request instance in the register() method so you can check for the url parameters.

    In your RegisterController.php add the register method:

    public function register(Request $request)
     {
         $this->validator($request->all())->validate();
    
         //Determine User type
         if($request->user_type === 'mentor'){
            event(new Registered($user = $this->create($request->all())));  
         }
    
         $this->guard()->login($user);
    
         return $this->registered($request, $user)
                         ?: redirect($this->redirectPath());
     }