title: Laravel 5.4 null csrf_token() when posting to route
body: <p>I'm sending an ajax post request, and with Laravel it seems that is done by creating a post route for it. I've set it up so a csrf token is put in the header automaticaly for every ajax request using ajaxSetup. I'm attempting to then catch that header on the backend and verify the tokens match.</p>
  
  <p>In my web routes (which automatically use the web middleware), this returns as expected:</p>
  
  <pre><code>Route::get('/test', function() {
      return csrf_token();
  });
  </code></pre>
  
  <p>However, when I post to a route via AJAX, like either of the below ways:</p>
  
  <p>Attempt 1:</p>
  
  <pre><code>Route::post('/test', 'AjaxController@test');
  </code></pre>
  
  <p>In the AjaxController construct, followed by an alert in the view:</p>
  
  <pre><code>var_dump(csrf_token().',hi'); die;
  </code></pre>
  
  <p>Response: ',hi' (csrf_token was null).</p>
  
  <p>Attempt 2:</p>
  
  <pre><code>Route::post('/test', ['test' =&gt; csrf_token().',hi', 'uses' =&gt; 'AjaxController@test']);
  
  $test = $request-&gt;route()-&gt;getAction()['test'];
  var_dump($test); die;
  </code></pre>
  
  <p>Response: ',hi' (csrf_token was null).</p>
  
  <p>What I seem to be running into is, with get requests csrf_token() is populated, on my post request, it is not.</p>
  
  <p>Any ideas?</p>