title: How to send csrf_token() inside AngularJS form using Laravel API?
body: <p>I am trying to build an angular + laravel rest application. I can get the views of my database. When I try to add new items. I get <code>500 error</code> telling me mismatch  csrf token. 
  My form layout is :</p>
  
  <pre><code>&lt;form class="form-horizontal" ng-submit="addItem()"&gt;
  
    &lt;input type="text" ng-model="itemEntry" placeholder="Type and hit Enter to add item"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is how I try to add item to database :</p>
  
  <pre><code>$scope.addItem = function(CSRF_TOKEN) {
      $http.post('/shop', { text: $scope.itemEntry, csrf_token: CSRF_TOKEN} ).success(function(data, status) {
          if(data) {
              var last = _.last($scope.items);
              _token = CSRF_TOKEN;
              $scope.items.push({text: $scope.itemEntry, bought: false, id: (last.id + 1) });
              $scope.itemEntry = '';
              console.log($scope.items);
          } else {
              console.log('There was a problem. Status: ' + status + '; Data: ' + data);
          }
      }).error(function(data, status) {
              console.log('status: ' + status);
          });
  
  }
  </code></pre>
  
  <p>Here is my filter that I use for my application: </p>
  
  <pre><code>Route::filter('csrf', function()
  {
      if (Session::token() != Input::get('_token'))
      {
          throw new Illuminate\Session\TokenMismatchException;
      }
  });
  </code></pre>
  
  <p>In my blade views I use this and it works :</p>
  
  <pre><code>&lt;input type="hidden" name="_token" value="{{ csrf_token() }}" /&gt;
  </code></pre>
  
  <p>How can I send the csrf_token when I use html forms? </p>
  
  <p>Thanks</p>
  
  <p>Edit 1 : 
  Adding header to post request like this does not give errors. </p>
  
  <pre><code>  $http({
      method  : 'POST',
      url     : '/shop',
      data    :  $scope.itemEntry,  // pass in data as strings
      headers : { 'Content-Type': 'application/x-www-form-urlencoded' }   
    });
  </code></pre>