title: Routes: Check if session exists in Laravel
body: <p>So in my <code>LoginController.php,</code> I started a session for different <code>post request variables</code> below where the session code is inside the authenticated function of auth.</p>
  
  <pre><code> protected function authenticated(Request $request, User $user){
       $request-&gt;session()-&gt;put('param1',$param1);
       $request-&gt;session()-&gt;put('param2',$param2);
       $request-&gt;session()-&gt;put('param3',$param3);
       .....
   }
  </code></pre>
  
  <p>and I easily access these session in my different controllers like this</p>
  
  <p><code>$request-&gt;session()-&gt;get('param1')</code></p>
  
  <p>and I also placed this code when logout triggers..</p>
  
  <p><code>session()-&gt;flush();</code></p>
  
  <p>But I need also to protect my <code>route</code> if these <code>session exists</code> or <code>not</code></p>
  
  <p>What I'm trying to do is to not allow the users not to access these routes if session is not exists <strong>web.php</strong></p>
  
  <pre><code>Route::group(['middleware'=&gt; ['auth']], function(){
  
  Route::get('/pay', 'PayController@index');
  Route::post('pay/getReceipt', 'PayController@getReceipt')-&gt;name('getReceipt');
  ....
  
  });
  </code></pre>