问题
I know that angular can integrate with some frameworks. I want to use angular version 4 into Laravel version 5.5 but I don't know how to setup the application. It is possible that I install angular CLI into Laravel project? Which solutions is the best for building app with angular ( integrate with framework or separate two projects)?
回答1:
I am assuming you have the understanding about Angular and Laravel.
I have used Angular(2+) and Laravel in many projects. Angular is for front-end development and Laravel for backend API.
It is very easy to integrate both Laraval and Angular.
There is "resources" directory in Laravel project. inside this, I used to keep the Angular code.
Use "ng build" command, this will create a "dist" directory. This directory keeps your all files(javascript, CSS, images and index file).
Laravel serves the app from "public" folder in the root directory of Laravel project.
Place the "dist" (that was created using "ng build" command) folder inside "public" directory.
if using Apache web server then set the public folder as a root folder and add a rewrite rule inside ".htaccess" file.
RewriteEngine On
RewriteRule index.html index.php
Now server will read "index.html" file that we place inside the public folder.
回答2:
I am actually working on an project with laravel and angular (v4). The project setup is very easy. We are using laravel for API development. With angular we create frontend page for userc/clients and backend page for administrator, which can manage the frontend page.
I like this separation of angular and laravel, because so you have very good control of API, Frontend (Client) and Backend (Administration). Other good thing on this separation is that you can share tasks between different developers.
I am sure that it is possible to install angular project into laravel project, but I think it will be hard to support this project setting in the feature.
回答3:
I've just released a simple npm tool for integrating Angular into Laravel. It's easy to use and provides fast basic integration - https://www.npmjs.com/package/laang
来源:https://stackoverflow.com/questions/48559445/how-can-angular-4-use-with-laravel-5-5-together