title: Having 2 forms on the same page in Laravel?
body: <p>I'm trying to tackle a "two forms on one page" issue with my PHP code, but its turning out to be more tirkcy than I expected, and just isn't behaving in the correct way as I thought it would.</p>
  
  <p>For the first form (Login) I'm using this if statement to determine if the message if for the Login.</p>
  
  <pre><code>@if(Session::has('message') &amp;&amp; Session::get('last_message_for') == 'login')
  &lt;div class="notification is-{{ Session::get('color') }}"&gt;
      &lt;i class="fa fa-times"&gt;&lt;/i&gt; &amp;nbsp;&amp;nbsp;{{ Session::get('message') }}
  &lt;/div&gt;
  @elseif($errors-&gt;first() &amp;&amp; Session::get('last_message_for') == 'login')
  &lt;div class="notification is-warning"&gt;
      &lt;i class="fa fa-times"&gt;&lt;/i&gt; &amp;nbsp;&amp;nbsp;{{ $errors-&gt;first() }}
  &lt;/div&gt;
  @endif
  </code></pre>
  
  <p>I've got the same code for my second form, but it just checks the <code>last_message_for</code> for a different value to 'login'.</p>
  
  <pre><code>@if(Session::has('message') &amp;&amp; Session::get('last_message_for') == 'modal')
  &lt;div class="modal is-active" id="modal-forgotPassword"&gt;
  @else 
  &lt;div class="modal" id="modal-forgotPassword"&gt;
  @endif
      &lt;div class="modal-background"&gt;&lt;/div&gt;
      &lt;div class="modal-card"&gt;
          &lt;header class="modal-card-head"&gt;
              &lt;p class="modal-card-title" id="open-modal"&gt;Forgot Password?&lt;/p&gt; &lt;button class="delete"&gt;&lt;/button&gt;
          &lt;/header&gt;
          &lt;form action="{{ route('frontend.guest.password.forgot') }}" method="post"&gt;
              &lt;input type="hidden" name="_token" value="{{ csrf_token() }}"&gt;
              &lt;section class="modal-card-body"&gt;
                  &lt;div class="content"&gt;
                      @if(Session::has('message') &amp;&amp; Session::get('last_message_for') == 'modal')
                      &lt;div class="notification is-{{ Session::get('color') }}"&gt;
                          &lt;i class="fa fa-times"&gt;&lt;/i&gt; &amp;nbsp;&amp;nbsp;{{ Session::get('message') }}
                      &lt;/div&gt;
                      @endif
                      &lt;div class="field"&gt;
                          &lt;p class="control has-icons-left"&gt;
                              &lt;input class="input" name="email" placeholder="Enter an email..." type="email"&gt;
                              &lt;span class="icon is-small is-left"&gt;&lt;i class="fa fa-envelope"&gt;&lt;/i&gt;&lt;/span&gt;
                          &lt;/p&gt;
                      &lt;/div&gt;
                      &lt;input type="hidden" name="_token" value="{{ csrf_token() }}"&gt;
                  &lt;/div&gt;
              &lt;/section&gt;
              &lt;footer class="modal-card-foot"&gt;
                  &lt;button class="button is-success" type="submit"&gt;&lt;i class="fa fa-sign-in"&gt;&lt;/i&gt; &amp;nbsp;&amp;nbsp;Send email&lt;/button&gt;
              &lt;/footer&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Now down to the issue, the Login part works perfectly fine and shows the error messages when there are any for it, but the second one isn't showing any errors when I have some.</p>
  
  <p>I'm using this to set the last_message_for</p>
  
  <pre><code>Session::put('last_message_for', 'login');
  </code></pre>
  
  <p>Here is the code for my second form:</p>
  
  <pre><code>public function onForgotPassword(Request $request) {
      $validator = Validator::make($request-&gt;all(), [
          'email' =&gt; 'required|email|exists:users,mail',
      ]);
  
      Session::put('last_message_for', 'modal');
  
      if ( $validator-&gt;fails()) {
          return redirect()-&gt;route('frontend.guest.login')-&gt;withErrors($validator-&gt;messages());;
      }
      else {
          Mail::to($request-&gt;input('email'))-&gt;send(new ForgotPasswordEmail());
          return redirect()-&gt;route('frontend.guest.login')-&gt;withMessage('Email Sent')-&gt;withColor('warning');
      }
  }
  </code></pre>