Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

markwu's avatar

Which way to integrate with Laravel and Angularjs?

Hi, I have a question about integration of laravel and angularjs (maybe other javascript framework).

  1. Does laravel only responsible for restful api to take care of data persistence? and angularjs take all route/view/curd stuff?

  2. Or laravel take care of all frontend/backend route/view/model/api/curd stuff, and angular only responsible for frontend UI interaction?

  3. Or just mixed two of these?

What's your concerns when choose the one than the other?

0 likes
7 replies
Dixens's avatar

My two cents: I usually go for option #2, ie angular dealing only with frontend. For instance, at the time being, we're developing an invoice app: the whole foundation is Laravel (routes, controllers, interfaces, repositories, service providers, models) and Angular is responsible for "real-time" calculation, Ajax calls, etc.

2 likes
RemiC's avatar

I usually build an API using Laravel and have Angular access it. Don't even think about mixin laravel views with your angular app. Just render one view file that bootstrap the angular app then just make restful calls from there.

Be sure to use ui-router for angular and restangular module as well, will make your life lot easier.

This tutorial is a really good starting point :

http://angular-tips.com/blog/2014/10/working-with-a-laravel-4-plus-angular-application/

2 likes
brayniverse's avatar

It's relative to what you're trying to achieve. If you are creating a full-featured application then I recommend using Laravel for a RESTful API and data persistence and using Angular for your UI and routing. As @RemiC suggested you can create a single view to "bootstrap" your Angular application and let Angular manage view loading, this will result in a speedier experience for your user because not all assets are downloaded each time a user navigates to another page.

If you are creating a basic website with only a few pages it wouldn't hurt just using Laravel to handle routing and using Angular for in-page interactions.

I switch between both types fairly often and there are a couple benefits to the first option.

  • You can switch out Laravel for another solution without having to transfer your templating
  • You can switch out Angular for another front-end framework or mobile app (iOS, Android)

I have had difficulty deciding upon an approach for managing authentication in an Angular app though. My current solution is to check for 403 responses from my RESTful API and redirect the user to a login page (generated by Laravel's routing). Here is an explanation of how to intercept API requests in Angular: http://stackoverflow.com/questions/25041929/angularjs-routeprovider-http-status-403

Hope this helps @markwu, let me know if you have any more questions :)

1 like
markwu's avatar

Wow, thanks for all @Dixens @RemiC @brayniverse of your valuable answers. Really helpful.

Still some issues I need to clarify:

  1. As I know, if I use laravel to take care of the route, I don't need to worry about the SEO, becasue the route is reachable. But If I use angularjs as my route engine, the SEO result will be bad.

    Does that mean for craw-able pages (like blog pages), I better use option #2, for admin page I better use option #1?

  2. Should I consider if browser does not support javascript? If the browser support javascript, I can handling the json data through angular route/controller and view. If the browser does not support javascript, I can redirect/link to full page with laravel route. Does that make sense?

RemiC's avatar

About #1 , it's a known weak point about Angular, but things are getting better now with google annoucing they're now crawling JS websites a lot better, and some tools like https://prerender.io/ emerging.

About #2, we're approaching 2015, I wouldn't ever bother with it.

Please or to participate in this conversation.