title: Laravel 5.1 randomly dropping session data
body: <p>I have a strange issue with a Laravel 5.1 application.</p>
  
  <p>Intermittently, it’s dropping session data. I’m detected this by writing some middleware that writes the contents of the session for that request to the log file. Although the session ID (<code>Session::getId()</code>) doesn’t change, the value of <code>_token</code> in the session data retrieved with <code>Session::all()</code> <em>does</em>.</p>
  
  <p>As I say, this happens intermittently. I can refresh the same URL multiple times, and then randomly on one refresh the session data’s gone, and the <code>_token</code> value’s different from the previous requests.</p>
  
  <p>What would cause this? I’ve also noticed the <code>flash</code> object isn’t in the “dropped” session data.</p>
  
  <p>Below is a snippet of the log. You can see the content of the <code>session_data</code> key randomly changes “shape” in the last two lines, but the session ID remains constant.</p>
  
  <p>Also, not sure if it’s pertinent, but I have <a href="https://github.com/barryvdh/laravel-debugbar" rel="nofollow noreferrer">DebugBar</a> enabled.</p>
  
  <p><a href="https://i.stack.imgur.com/5bUjD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5bUjD.png" alt="Screen-shot"></a></p>
  
  <p><strong>UPDATE:</strong> Through debugging, I’ve found that on some page loads the session is completely <em>empty</em>, as in, no <code>_token</code> (hence a new one getting generated). Nothing.</p>