title: Laravel Redirect::back()->withErrors() not working in Test
body: <p>Okay I'm having real trouble writing a functional test for a "incorrect credentials" login i.e. missing password.</p>
  
  <p>For background here is my route configuration:</p>
  
  <pre><code>Route::get('login', array('as' =&gt; 'login', 'uses' =&gt; 'SessionController@create'));
  Route::resource('session', 'SessionController');
  </code></pre>
  
  <p>Here is the content in my SessionController::store() method:</p>
  
  <pre><code>public function store()
  {
  
      $credentials = Input::only('email', 'password');
  
      try {
          $this-&gt;loginForm-&gt;validate($credentials);
  
          if (!Auth::attempt(array('email' =&gt; $credentials['email'], 'password' =&gt; $credentials['password']))) {
              return Redirect::back()-&gt;exceptInput('password')-&gt;with('flash_message', 'Invalid credentials');
          }
  
          return Redirect::to('/')-&gt;with('flash_message', 'Welcome back');
  
      }
      catch (FormValidationException $e)
      {
          return Redirect::back()-&gt;exceptInput('password')-&gt;withErrors($e-&gt;getErrors());
      }
  
  }
  </code></pre>
  
  <p>The above store() controller works perfectly in the browser(!) when I submit a form with POST action to /session. A form validation error is thrown and I get redirected back to /login with the $errors variable in my view correctly populated with the relevant message ("The password field is required"):</p>
  
  <pre><code>@foreach($errors-&gt;all() as $error)
      {{ $error }}
  @endforeach
  </code></pre>
  
  <p>However when trying to replicate the expected working behaviour above in a functional test I have a problem. Here is the basic outline of my test:</p>
  
  <pre><code>public function testIncorrectCredentialsLogin()
  {
      $this-&gt;client-&gt;request('GET', '/login');
  
      $this-&gt;assertTrue($this-&gt;client-&gt;getResponse()-&gt;isOk());
  
      $credentials = array(
          'email' =&gt; 'me@example.com',
          'password' =&gt; ''
      );
  
      $this-&gt;client-&gt;request('POST', '/session', $credentials);
  
      $this-&gt;assertRedirectedTo('login', array('errors'));
  
      $crawler = $this-&gt;client-&gt;followRedirect();
  
      $this-&gt;assertSessionHasErrors();
  
      $this-&gt;assertHasOldInput();
  
      $this-&gt;assertViewHas('errors'); // Fails
  
  }
  </code></pre>
  
  <p>In my functional test I try to replicate what happens successfully in the browser. I first GET /login and then make a /POST to SessionController::store() with missing credentials which results in a validation error and a redirect back to /login. All okay so far but when I follow this redirect back I look within the rendered login page content/HTML and I have no $errors variable set and thus no messages available in the session/displayed in the page.</p>
  
  <p>Can anyone advise what might be happening?</p>
  
  <p>Thanks in advance.</p>