title: RESTful API using Laravel with AngularJS
body: <p>I'm trying to figure out something. Most of the time, the way I create a RESTful API is by doing something like this:</p>
  
  <p><strong>Route:</strong></p>
  
  <pre><code>Route::get('/news', 'NewsController@show');
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>class NewsController extends Controller
  {
      public function show()
      {
          $news= News::all();
  
          return view('newsview', compact('news'));
      }
  }
  </code></pre>
  
  <p><strong>Blade:</strong></p>
  
  <pre><code>@foreach ($news as $n)
  &lt;li&gt; {{$n-&gt;title}} {{$n-&gt;author}}&lt;/li&gt;
  @endforeach
  </code></pre>
  
  <p>And now, I'm trying to learn <code>AngularJS</code>. The way I see some tutorials on the web is they are using <code>AngularJS</code> as <code>front-end</code> and <code>Laravel</code> as the <code>back-end</code>. And now I see something like this:</p>
  
  <p><strong>Route:</strong></p>
  
  <pre><code>Route::get('/news', 'NewsController@show');
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>class NewsController extends Controller
  {
      public function show()
      {
          return News::all();
      }
  }
  </code></pre>
  
  <p><strong>HTML/JS:</strong></p>
  
  <pre><code>&lt;div ng-app="myApp" ng-controller="newsCtrl"&gt; 
  
  &lt;ul&gt;
    &lt;li ng-repeat="x in news"&gt;
      {{ x.title + ', ' + x.author }}
    &lt;/li&gt;
  &lt;/ul&gt;
  
  &lt;/div&gt;
  
  &lt;script&gt;
  var app = angular.module('myApp', []);
  app.controller('newsCtrl', function($scope, $http) {
      $http.get("/news")
      .success(function(response) {$scope.news = response.records;});
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>What's the advantage of using one to another? I'm really interested in using <code>AngularJS</code>.</p>