1

I am making an app and I was wondering what is a better way to approach this. I want to use Laravel as the backend, and AngularJS as the frontend.

Should I then leave the entire rendering and View completely to AngularJS and only use Laravel through AJAX calls? Or should I still load the basics from Laravel, and use AngularJS to enhance the experience?

1 Answer 1

1

Yes. You could use Laravel as RESTFul API and consume from client without using blade (so if you want it)

Here example:

class PostController extends \BaseController {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
         return Post::orderBy('created_at', 'desc');
    }
}

service in angular: ( I use Restangular lib, but you can use $http)

app.factory("PostsService", function(Restangular) {
  return {
    /*
    * GET /posts -> Trae todos los posts
    */
    all: function() {
      return Restangular.all('posts').getList();
    }
  }
});

controller angular:

app.controller('HomeController', function($scope, PostsService){
  PostsService.all().then(function(posts){
    $scope.posts = posts.data;
  });

});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.