title: Laravel Auth modify for two kinds of users
body: <p>I'm currently trying to modify the laravel Auth two be able to register two different kinds of users, a seller and a buyer. Both have the same form, except one field, that only the seller has, called <code>companyName</code>.</p>
  
  <p>So what I did is putting a dropdown for registration instead of the normal register button, this is what I got there:</p>
  
  <pre><code>&lt;div class="dropdown"&gt;
                              &lt;button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"&gt;
                                  Registrieren
                                  &lt;span class="caret"&gt;&lt;/span&gt;
                              &lt;/button&gt;
                              &lt;ul class="dropdown-menu" aria-labelledby="dropdownMenu1"&gt;
                              &lt;li&gt;
                                  &lt;a href="{{url('/register/customer')}}"&gt;Als Käufer&lt;/a&gt;
                                  &lt;a href="{{url('/register/seller')}}"&gt;Als Händler&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;/ul&gt;
                          &lt;/div&gt;
  </code></pre>
  
  <p>Then I made a route for this two kinds of registrations, like this:</p>
  
  <pre><code>Route::get('/register/{userType}', 'Auth\RegisterController@showRegistrationForm');
  </code></pre>
  
  <p>In the controller then I simply overwrote this <code>showRegistrationForm</code> function to pass the <code>userType</code> into my view, just like that:</p>
  
  <pre><code> public function showRegistrationForm($userType)
      {
          return view('auth.register', ['userType'=&gt; $userType]);
      }
  </code></pre>
  
  <p>And in my view, I got this:</p>
  
  <pre><code>@extends('master')
  
  @section('content')
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-8 col-md-offset-2"&gt;
                  &lt;div class="panel panel-default"&gt;
                      &lt;div class="panel-heading"&gt;Registrieren
                          als &lt;?php if ($userType == 'customer') echo "Käufer";if ($userType == 'seller') echo "Verkäufer";?&gt;&lt;/div&gt;
                      &lt;div class="panel-body"&gt;
                          &lt;form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}"&gt;
                              {{ csrf_field() }}
  
                              &lt;div class="form-group{{ $errors-&gt;has('sex') ? ' has-error' : '' }}"&gt;
                                  &lt;label for="sex" class="col-md-4 control-label"&gt;Anrede&lt;/label&gt;
                                  &lt;div class="col-md-6"&gt;
  
                                      &lt;select class="form-control" id="sex"&gt;
                                          &lt;option value="male"&gt;Herr&lt;/option&gt;
                                          &lt;option value="female"&gt;Frau&lt;/option&gt;
                                  &lt;/select&gt;
                                  &lt;/div&gt;
  
                                  @if ($errors-&gt;has('sex'))
                                      &lt;span class="help-block"&gt;
                                          &lt;strong&gt;{{ $errors-&gt;first('sex') }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                  @endif
                              &lt;/div&gt;
  
                              &lt;div class="form-group{{ $errors-&gt;has('name') ? ' has-error' : '' }}"&gt;
                                  &lt;label for="firstName" class="col-md-4 control-label"&gt;Vorname&lt;/label&gt;
  
                                  &lt;div class="col-md-6"&gt;
                                      &lt;input id="firstName" type="text" class="form-control" name="firstName"
                                             value="{{ old('firstName') }}" required autofocus&gt;
  
                                      @if ($errors-&gt;has('firstName'))
                                          &lt;span class="help-block"&gt;
                                          &lt;strong&gt;{{ $errors-&gt;first('firstName') }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                      @endif
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class="form-group{{ $errors-&gt;has('name') ? ' has-error' : '' }}"&gt;
                                  &lt;label for="name" class="col-md-4 control-label"&gt;Nachname&lt;/label&gt;
  
                                  &lt;div class="col-md-6"&gt;
                                      &lt;input id="name" type="text" class="form-control" name="name"
                                             value="{{ old('name') }}" required autofocus&gt;
  
                                      @if ($errors-&gt;has('name'))
                                          &lt;span class="help-block"&gt;
                                          &lt;strong&gt;{{ $errors-&gt;first('name') }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                      @endif
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;?php if ($userType == 'seller'){ ?&gt;
                              &lt;div class="form-group{{ $errors-&gt;has('companyName') ? ' has-error' : '' }}"&gt;
                                  &lt;label for="companyName" class="col-md-4 control-label"&gt;Firmenname&lt;/label&gt;
  
                                  &lt;div class="col-md-6"&gt;
                                      &lt;input id="companyName" type="text" class="form-control" name="companyName"
                                             value="{{ old('companyName') }}" required autofocus&gt;
  
                                      @if ($errors-&gt;has('companyName'))
                                          &lt;span class="help-block"&gt;
                                          &lt;strong&gt;{{ $errors-&gt;first('companyName') }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                      @endif
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;?php } ?&gt;
  
                              &lt;div class="form-group{{ $errors-&gt;has('email') ? ' has-error' : '' }}"&gt;
                                  &lt;label for="email" class="col-md-4 control-label"&gt;E-Mail Addresse&lt;/label&gt;
  
                                  &lt;div class="col-md-6"&gt;
                                      &lt;input id="email" type="email" class="form-control" name="email"
                                             value="{{ old('email') }}" required&gt;
  
                                      @if ($errors-&gt;has('email'))
                                          &lt;span class="help-block"&gt;
                                          &lt;strong&gt;{{ $errors-&gt;first('email') }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                      @endif
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class="form-group{{ $errors-&gt;has('password') ? ' has-error' : '' }}"&gt;
                                  &lt;label for="password" class="col-md-4 control-label"&gt;Passwort&lt;/label&gt;
  
                                  &lt;div class="col-md-6"&gt;
                                      &lt;input id="password" type="password" class="form-control" name="password" required&gt;
  
                                      @if ($errors-&gt;has('password'))
                                          &lt;span class="help-block"&gt;
                                          &lt;strong&gt;{{ $errors-&gt;first('password') }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                      @endif
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class="form-group{{ $errors-&gt;has('password_confirmation') ? ' has-error' : '' }}"&gt;
                                  &lt;label for="password-confirm" class="col-md-4 control-label"&gt;Passwort
                                      wiederholen&lt;/label&gt;
  
                                  &lt;div class="col-md-6"&gt;
                                      &lt;input id="password-confirm" type="password" class="form-control"
                                             name="password_confirmation" required&gt;
  
                                      @if ($errors-&gt;has('password_confirmation'))
                                          &lt;span class="help-block"&gt;
                                          &lt;strong&gt;{{ $errors-&gt;first('password_confirmation') }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                      @endif
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div style="display:none;" class="form-group{{ $errors-&gt;has('role') ? ' has-error' : '' }}"&gt;
                                  &lt;label for="role" class="col-md-4 control-label"&gt;Deine Rolle:&lt;/label&gt;
  
                                  &lt;div class="col-md-6"&gt;
                                      &lt;input name="role" type="radio"
                                             &lt;?php if ($userType == 'customer') echo "checked";?&gt; value="Käufer"&gt;&amp;nbsp;Käufer&lt;br/&gt;
                                      &lt;input name="role" type="radio"
                                             &lt;?php if ($userType == 'seller') echo "checked";?&gt; value="Verkäufer"&gt;&amp;nbsp;Verkäufer
  
                                      @if ($errors-&gt;has('role'))
                                          &lt;span class="help-block"&gt;
                                          &lt;strong&gt;{{ $errors-&gt;first('role') }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                      @endif
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class="form-group"&gt;
                                  &lt;div class="col-md-6 col-md-offset-4"&gt;
                                      &lt;button type="submit" class="btn btn-primary"&gt;
                                          Registrieren
                                      &lt;/button&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/form&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  @endsection
  </code></pre>
  
  <p>So mostly basic, just few more fields then with the auth without modification and the <code>companyName</code> only showing up when accessed over the route <code>/register/seller</code>.</p>
  
  <p>My RegisterController is of course also a bit modified, or especially the create function, it looks like this now:</p>
  
  <pre><code> protected function create(array $data)
      {
          $user = User::create([
              'name' =&gt; $data['name'],
              'firstName' =&gt; $data['firstName'],
              'sex' =&gt; $data['sex'],
              'email' =&gt; $data['email'],
              'username' =&gt; $data['username'],
              'password' =&gt; bcrypt($data['password']),
              'role' =&gt; $data['role'],
              'templateURL' =&gt; ""
          ]);     
  
          if($data['role'] == 'Verkäufer'){
              Complaint::create([
                 'user_id' =&gt; $user-&gt;id,
                 'complaintCount' =&gt; 0
              ]);
          }
  
          switch($data['role']){
              case 'Käufer':
                  $user-&gt;attachRole(2);
                  break;
              case 'Verkäufer':
                  $user-&gt;attachRole(3);
                  $user-&gt;companyName = $data['companyName'];
                  $user-&gt;save();
                  break;
              default:
                  $user-&gt;attachRole(2);
                  break;
          }
  
  
          return $user;
      }
  </code></pre>
  
  <p>And now comes the problem: As you can see, in my "invidual" views, which is basically just one anyway, I still post to the url <code>/register</code>, which I thought should work, but it doesn't.... Any ideas why this is not working? I also tried to add individual routes, so something like that:</p>
  
  <pre><code>Route::post('/register/seller', 'Auth\RegisterController@create');
  Route::post('/register/buyer', 'Auth\RegisterController@create');
  </code></pre>
  
  <p>but thats not working as well. In both cases, I just get the same window back, as if there was an error (so my data still entered (expect the password), but nothing is registered or entered in the db, but as well there are no errors showing up, neither in my view, nor in the console.</p>
  
  <p>What's interesting as well is the network tab, it seems like it definetely sends the request to <code>/register</code> as it shows up there with status code 302, but as well there's the route <code>/register/customer</code> again, and I'm wondering why...What's also interesting is that I think that somehow it kinda works, as if I enter a password with less then 6 characters or 2 different passwords, I get an error, so somehow the form seems to be posted, but nothing is entered into the db....</p>
  
  <p>Any ideas why this happens like this and whats the problem?</p>