title: CSRF token mismatch even after providing the token in the post Laravel 5
body: <p>I am trying to post using ajax in laravel 5.
  I get CSRF token mismatch exception.
  I have looked around and found may such issues, but in this case I did include all the code necessary.</p>
  
  <p>Please take a look at my code.</p>
  
  <p>View</p>
  
  <pre><code>{!! Form::open(array('url'=&gt;'admin/index','method'=&gt;'POST', 'id'=&gt;'addrole')) !!}
  &lt;div class="control-group"&gt;
    &lt;div class="controls"&gt;
       {!! Form::text('user','',array('id'=&gt;'','class'=&gt;'form-control span6','placeholder' =&gt; 'Username')) !!}
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="control-group"&gt;
    &lt;div class="controls"&gt;
        {!! Form::text('role','faculty',array('class'=&gt;'form-control span6', 'placeholder' =&gt; 'User Role')) !!}
        &lt;input type="hidden" name="_token" value="{{ csrf_token()}}"&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  {!! Form::button('Submit', array('class'=&gt;'send-btn')) !!}
  {!! Form::close() !!}
  
  &lt;script type="text/javascript"&gt;
  
      $.ajaxSetup({
         headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
      });
  
      $(document).ready(function(){
          $('.send-btn').click(function(){
              $.ajax({
                  url: 'index',
                  type: "post",
                  data: {
                      '_token': $('input[name="_token"]').val(),
                      'user':$('input[name=user]').val(),
                      'role':$('input[name=role]').val()
                  }, //, '_token': $('input[name=_token]').val()
                  success: function(data) {
                      alert(data);
                  }
              });
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>I have provided the token in hidden input and I include this in my post.</p>
  
  <p>I do have a meta in head as follows.</p>
  
  <pre><code>&lt;meta name="_token" content="{!! csrf_token() !!}"/&gt;
  </code></pre>
  
  <p>The following is my controller.</p>
  
  <pre><code>public function index()
  {
      if(Request::ajax()) {
          $data = Input::all();
          print_r($data);die;
      }
  }
  </code></pre>
  
  <p>This one is just for testing, nothing much here.
  My routes are as follows</p>
  
  <pre><code>Route::get('admin/index', function() {
    return View::make('admin');
  });
  Route::post('admin/index', 'AdminController@index');
  </code></pre>
  
  <p>Please help me resolve this issue</p>
  
  <p>this is the output in logs.</p>
  
  <pre><code>[2015-11-12 09:04:31] local.ERROR: exception 'Illuminate\Session\TokenMismatchException' in /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:46
  Stack trace:
  #0 /var/www/html/vidman-laravel/app/Http/Middleware/VerifyCsrfToken.php(17): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
  #1 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(125): App\Http\Middleware\VerifyCsrfToken-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
  #2 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(55): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  #3 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(125): Illuminate\View\Middleware\ShareErrorsFromSession-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
  #4 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(61): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  #5 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(125): Illuminate\Session\Middleware\StartSession-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
  #6 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(36): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  #7 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(125): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
  #8 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(40): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  #9 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(125): Illuminate\Cookie\Middleware\EncryptCookies-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
  #10 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(42): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  #11 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(125): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
  #12 [internal function]: Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  #13 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(101): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
  #14 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(115): Illuminate\Pipeline\Pipeline-&gt;then(Object(Closure))
  #15 /var/www/html/vidman-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(84): Illuminate\Foundation\Http\Kernel-&gt;sendRequestThroughRouter(Object(Illuminate\Http\Request))
  #16 /var/www/html/vidman-laravel/public/index.php(53): Illuminate\Foundation\Http\Kernel-&gt;handle(Object(Illuminate\Http\Request))
  #17 {main} 
  </code></pre>
  
  <p>The following is my browser console post header and the in-page csrf token don't match. Please look below</p>
  
  <p><a href="https://i.stack.imgur.com/9xcfZ.png" rel="nofollow noreferrer">The token in the page ==> input type="text" name="_token" value="{{ csrf_token()}}"</a></p>
  
  <p><a href="https://i.stack.imgur.com/BSTP2.png" rel="nofollow noreferrer">Browser post header</a></p>