title: Laravel : Redirect with data
body: <p>I am trying to send data on <code>with()</code> but at the view the login page refreshes but doesn't show anything. I have tried it almost with everything, I have read many questions tried almost every way. </p>
  
  <p>My controller, The if condition is working .</p>
  
  <pre><code>public function authenticate(Request $request)
  {
      $validator = Validator::make(Input::get(),
          [
              'password' =&gt; 'required',
              'username' =&gt; 'required'
          ]
      );
      if ($validator-&gt;fails()) {
          return redirect()
              -&gt;back()
              -&gt;withErrors($validator-&gt;errors())
              -&gt;with('message', 'Invalid Username or Password.')
              -&gt;with('form', 'login')
              -&gt;withInput(\Input::except('password'));
      }
      $user = array(
          'name' =&gt; Input::get('username'),
          'password' =&gt; Input::get('password')
      );
      if (Auth::attempt($user)) {
          return redirect()-&gt;intended('dashboard');
      } else {
          $request-&gt;session()-&gt;put('error_message', 'Incorrect email or password');
          $request-&gt;session()-&gt;put('form', 'login');
          return redirect()
              -&gt;back();
  
      }
  } 
  </code></pre>
  
  <p>And my view is :</p>
  
  <pre><code>    &lt;form class="login-form" method="post" style="{{{ Session::get('form', 'login') == 'login' ? 'display:block' : 'display:none;' }}}"&gt;
      &lt;input type="hidden" name="_token" value="{{ csrf_token() }}"&gt;
      &lt;h3 class="form-title"&gt;Login to your account&lt;/h3&gt;
      &lt;div class="alert alert-danger {{{ (Session::has('message') &amp;&amp; Session::get('form', 'login') == 'login') ? '' : 'display-hide' }}}"&gt;
          &lt;button class="close" data-close="alert"&gt;&lt;/button&gt;
  
          &lt;span&gt;
              {!! Session::has('message') ? Session::get('message') : 'Please correct your fields.' !!}
          &lt;/span&gt;
  
          &lt;span&gt;
              {!! session()-&gt;has('error_message') ? session('error_message') : 'Please correct your fields.' !!}
          &lt;/span&gt;
      &lt;/div&gt;
      &lt;div class='form-group {{ $errors-&gt;has("username") ? "has-error":"" }}'&gt;
          &lt;!--ie8, ie9 does not support html5 placeholder, so we just show field title for that--&gt;
          &lt;label class="control-label visible-ie8 visible-ie9"&gt;@Username&lt;/label&gt;
          &lt;div class="input-icon"&gt;
              &lt;i class="fa fa-envelope"&gt;&lt;/i&gt;
              {!! Form::text('username', '', ['class' =&gt; 'form-control placeholder-no-fix', 'placeholder' =&gt; 'Username']) !!}
              &lt;span class="help-block"&gt; {{ $errors-&gt;first("username") }} &lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class='form-group {{ $errors-&gt;has("password") ? "has-error":"" }}'&gt;
          &lt;label class="control-label visible-ie8 visible-ie9"&gt;Password&lt;/label&gt;
          &lt;div class="input-icon"&gt;
              &lt;i class="fa fa-lock"&gt;&lt;/i&gt;
              {!! Form::password('password', ['class' =&gt; 'form-control placeholder-no-fix', 'placeholder' =&gt; 'Password']) !!}
              &lt;span class="help-block"&gt; {{ $errors-&gt;first("password") }} &lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-actions"&gt;
          &lt;!--&lt;label class="checkbox"&gt;
          &lt;input type="checkbox" name="remember" value="1"/&gt; Remember me &lt;/label&gt;--&gt;
          &lt;button type="submit" class="btn red pull-right"&gt;
          Login &lt;i class="m-icon-swapright m-icon-white"&gt;&lt;/i&gt;
          &lt;/button&gt;
      &lt;/div&gt;
      &lt;br/&gt;
      &lt;div class="forget-password"&gt;
          &lt;h4&gt;Forgot your password ?&lt;/h4&gt;
          &lt;p&gt;
              &lt;a href="javascript:;" id="forget-password"&gt;Reset&lt;/a&gt; your account login info.
          &lt;/p&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Routes.php have these routes:</p>
  
  <pre><code>Route::group(['middleware' =&gt; 'guest'], function ()
  {
      // login routes
  
      Route::get('/login', ['as' =&gt; 'login', 'uses' =&gt;  "CommonController@showLogin"]);
      Route::post('/login', ['uses' =&gt;  "CommonController@authenticate"]);
  
      Route::post('/reset', "Auth\PasswordController@postEmail");
      Route::get('/password/reset/{token}', 'CommonController@showReset');
      Route::post('/password/reset', 'Auth\PasswordController@postReset');
  
  });
      Route::get('/welcome', 'HomeController@index');
  
  Route::group(['middleware' =&gt; ['auth']], function ()
  {
      // COMMONS
      Route::get('/', 'CommonController@index');
      Route::get('/dashboard', ['as' =&gt; 'dashboard', 'uses' =&gt; 'CommonController@routeDashboard']);
      Route::get('/logout', ['as' =&gt; 'logout', 'uses' =&gt;  "CommonController@logout"]);
  
  
  
      Route::group(['as' =&gt; 'admin::', 'middleware' =&gt; 'role:admin'], function ()
      {
  
          // USERS
          Route::group(['as' =&gt; 'users::', 'prefix' =&gt; 'users'], function ()
          {
              Route::get('/', ['as' =&gt; 'manage', 'uses' =&gt; 'AdminController@showManageUsers']);
              Route::post('handle', ['as' =&gt; 'handle', 'uses' =&gt; 'AdminController@handleUsers']);
  
              Route::get('new', ['as' =&gt; 'new', 'uses' =&gt; 'AdminController@newUser']);
              Route::post('new', ['uses' =&gt; 'AdminController@newUserSave']);
  
              Route::get('edit-basic/{id}', ['as' =&gt; 'edit_basic', 'uses' =&gt; 'AdminController@editUserBasic']);
              Route::post('edit-basic/{id}', ['uses' =&gt; 'AdminController@editUserBasicSave']);
  
              Route::get('edit-historical/{id}', ['as' =&gt; 'edit_historical', 'uses' =&gt; 'AdminController@editUserHistorical']);
              Route::post('edit-historical/{id}', ['uses' =&gt; 'AdminController@editUserHistoricalSave']);
  
              Route::post('validate-username', ['as' =&gt; 'validate_username', 'uses' =&gt; 'AdminController@validateUsername']);
              Route::post('validate-email/{id?}', ['as' =&gt; 'validate_email', 'uses' =&gt; 'AdminController@validateEmail']);
          });
  
      });
  
  });
  </code></pre>
  
  <p>On wrong username and password the message doesn't show up.</p>