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

shanely's avatar

How to use angular in Laravel

Hi, I want to try using angular in laravel is there a tutorial for this I am using Laravel 5.2 the latest release...can someone help me how to install angular in laravel

0 likes
7 replies
EliyaCohen's avatar

I tried to use Angular on Laravel too, but the thing is that I misunderstood the idea of Angular. It doesn't matter on which framework you're working on. The only thing you need from Laravel is to be served as API. Don't take this as a final answer, I learned this from my own experience. If you try to combine Laravel and Angular together, It will get messy as hell.

ShaunL's avatar

@shanely I'm not sure of any tutorials but angular is strictly client based so there shouldn't be much installation involved outside of your favorite package manager. Basically your going to serve up your index page that links to all the angular scripts in your resources/views folder, then in your /public folder your going to have all of your project's custom scripts and views for angular.

I've toyed around with angular, it was a pain to learn, I hope angular 2 has a less steep learning curve. I agree with @EliyaCohen that it could get messy with laravel. One path you could take is to leverage lumen for your API backend then have angular hosted somewhere else that would just tap into your API. I've never done this before and have little experience with lumen but i'm sure there are tutorials out there. Laravel is the full package with blade and everything while lumen is a slimmed down version of laravel for APIs.

Hope that helps a little bit :)

Gerard's avatar

You don't need anything special, use ng-app and ng-controller as usual in your views and <link> the corresponding js files.

In blade templates use @{{ var }} for angularjs variables and {{ $var}} for laravel variables.

Aferz29's avatar

I know you can do it if you want but, why would you need that?

If you try to combine Laravel blade templating with angular templating you will slow down your app unnecessarily.

Angular was made to delegate to the client the work of building the whole app(Excepting data, of course). It doesn't need the server to create and render the html's. If you involve the server in views creation you are preprocessing your HTML with blade and later, on the client, it's rendered again by Angular.

The best way to handle Laravel + Angular is serving data by a Laravel( or Lumen ) API / Web service and let Angular render the views. The other ways is just senseless. If you feel better coding templates in Blade, maybe Angular is not what are you looking for your application.

Cheers.

1 like
mrashidtufail's avatar

@shanely @eliyacohen @shaunl @gerard @cizario @aferz29 what i understand from this conversation is that the ideal project structure of a project which has php/laravel/lumen as backend tech and angular as frontend.

project: backend - lumen (as it is serving apis only ....then why should we use laravel) frontend - angular but frontend should have (backend for frontend for better authentication )

kinldy share your thoughts as it will be great help for me and my team......

Please or to participate in this conversation.