title: Laravel 4 RESTful API with Angular.js
body: <p>I have a <strong><em>RESTful API</em></strong> based application with <strong><em>Laravel 4</em></strong> and <strong><em>Angular.js</em></strong>.
  The application's CRUD processes are handled by angularjs $http service.</p>
  
  <h1>The Backend Side (Laravel 4):</h1>
  
  <h2>Routing : app/routes.php</h2>
  
  <pre><code>//.....
  Route::group(array('prefix' =&gt; 'api/v1', 'before' =&gt; 'auth.basic'), function()
  {
      //....
      Route::resource('pages', 'PagesController');
      //....
  });
  //.....
  </code></pre>
  
  <h2>Controller : app/controllers/api/PageController.php</h2>
  
  <pre><code>&lt;?php
  
  //.....
  class PagesController extends BaseController {
    //......
    public function update($id) {
          $page = Page::find($id);
  
          if ( Request::get('title') )
          {
              $page-&gt;title = Request::get('title');
          }
  
          if ( Request::get('slug') )
          {
              $page-&gt;slug = Request::get('slug');
          }
  
          $page-&gt;save();
  
          return Response::json(array(
              'error' =&gt; false,
              'message' =&gt; 'Page Updated'),
              200
          );
    }
    //......
  }
  </code></pre>
  
  <h2>Calling : cURL</h2>
  
  <p>This update function can be accessed using cURL method also.</p>
  
  <pre><code>curl -i -X PUT --user admin:admin -d 'title=Updated Title' localhost/laravel/index.php/api/v1/pages/2
  </code></pre>
  
  <h1>Front-end : HTML</h1>
  
  <pre><code>&lt;!-- Top Code --&gt;
  &lt;!-- From to Add/Edit Pages --&gt;
  &lt;form class="form-horizontal" role="form" ng-show="edit" ng-submit="updatePage(entry)"&gt;
  
    &lt;!-- Page Title --&gt;   
    &lt;div class="form-group"&gt;
      &lt;label class="col-lg-2 control-label"&gt;Page Title&lt;/label&gt;
      &lt;div class="col-lg-4"&gt;
        &lt;input type="text" class="form-control" value="{{entry.title}}" ng-model="entry.title"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;!-- Slug --&gt;
    &lt;div class="form-group"&gt;
      &lt;label class="col-lg-2 control-label"&gt;Slug&lt;/label&gt;
      &lt;div class="col-lg-4"&gt;
        &lt;input type="text" class="form-control" value="{{entry.slug}}" ng-model="entry.slug"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
  
    &lt;div class="form-group"&gt;
      &lt;div class="col-lg-offset-2 col-lg-10"&gt;
        &lt;button type="submit" class="btn btn-primary"&gt;Update&lt;/button&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
  &lt;/form&gt;
  &lt;!-- Bottom Code --&gt;
  </code></pre>
  
  <h2>Client-side : angularjs</h2>
  
  <pre><code>// ......
  function pageCtrl($scope, $http, Data) {
    //.........
    $scope.updatePage = function(entry) {
  
  
          $http({method: 'PUT', url: Data.root_path + 'api/v1/pages/'+id}).
          success(function(data, status, headers, config) {
              //
          }).
          error(function(data, status, headers, config) {
              //
          });
  
    }
    //.........
  }
  </code></pre>
  
  <h1>Question:</h1>
  
  <ol>
  <li>How can I pass my form data(more than one values) to the $http.put request
  here ?</li>
  <li>How can I access the PUT request data in Laravel 4 Controller ? Can
  I use Input::get() ?</li>
  </ol>