title: Handling data response from $resource in angular js
body: <p>I have a <code>RESTful</code> application with <code>Laravel 4</code> and <code>Angular JS</code>.</p>
  
  <p>In my Laravel Controller,</p>
  
  <pre><code>public function index() {
  
    $careers = Career::paginate( $limit = 10 );
  
    return Response::json(array(
      'status'  =&gt; 'success',
      'message' =&gt; 'Careers successfully loaded!',
      'careers' =&gt; $careers-&gt;toArray()),
      200
    );
  }
  </code></pre>
  
  <p>And the angular script,</p>
  
  <pre><code>var app = angular.module('myApp', ['ngResource']);
  
  app.factory('Data', function(){
      return {
          root_path: "&lt;?php echo Request::root(); ?&gt;/"
      };
  });
  
  app.factory( 'Career', [ '$resource', 'Data', function( $resource, Data ) {
     return $resource( Data.root_path + 'api/v1/careers/:id', { id: '@id'});
  }]);
  
  function CareerCtrl($scope, $http, Data, Career) {
  
      $scope.init = function () {
          $scope.careers = Career.query(); 
      };
  }
  </code></pre>
  
  <p>Here I am little confused to handle the response data to assign to scope variable, now I am getting empty array <code>[]</code> in <code>$scope.careers</code>. And also How can I handle success and error to show some messages like the following normal <code>$http service</code>,</p>
  
  <pre><code>$scope.init = function () {
  
      Data.showLoading(); // loading progress
      $http({method: 'GET', url: Data.root_path + 'api/v1/careers'}).
      success(function(data, status, headers, config) {
          Data.hideLoading();
          $scope.careers = data.careers.data;
      }).
      error(function(data, status, headers, config) {
  
          if(data.error.hasOwnProperty('message')) {
              errorNotification(data.error.message); 
          } else {
              errorNotification();
          }
  
          $scope.careers = [];
      });
  };
  </code></pre>
  
  <p>See my request in console using $resource.</p>
  
  <p><img src="https://i.stack.imgur.com/FglF5.png" alt="enter image description here"></p>