1

I want to create a really simple SPA with Angularjs and Laravel 4 as an API in the background. I'll have some simple posts and categories (a blog actually) with some static pages. I want to call laravel API inside angular to get the information I want. How can I organize the code to do it properly? Maybe put the laravel to a subdomain and the angular app to the main domain? Is it a good way? I want to separate these frameworks and use laravel only for api service. Thanks for your advices.

3
  • Trying to make sure I understand the question. You want to use laravel for the mvc, but instead of returning html views you just want it to take care of persistence and then return whether or not whatever operation your requested was successfully performed? Commented Nov 27, 2013 at 18:49
  • I want to do everything with angular and laravel is just a separated service to response the requests made by the angular app Commented Nov 27, 2013 at 18:53
  • Ok, I posted an answer below that I think answers your question. If there's anymore confusion I'd be happy to clarify as best I can. Commented Nov 27, 2013 at 18:54

1 Answer 1

1

You can use laravel's built in restful controllers as a way of building your backend api.

Then you just have your angular js make ajax calls to whatever route you define to that controller. Then instead of having laravel return views using View::make, you have it return a response and I'm assuming returning json would be the best option. return Response::json(array('userId' => '1', 'operation' => 'UpdateUser', 'success' => 'true'));

Implemented this way, laravel acts strictly as an API and angular js acts as the intermediary between your user and the laravel api.

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.