Multiple Laravel 5 and AngularJS Applications

I am currently working on a project with several loosely coupled modules (20+), and I decided to go with Laravel 5 and AngularJs. I am using the yoman angularify generator for AngularJS. I cannot decide on the structure of the application, I would ideally want each submodule to be a different application, since it will be easy for developers to work on individual applications independently.

mylab/ app/ Http/ Controllers/ SomeController.php # API that will be used across all apps ... public/ bower_components/ angular/ bootstrap/ scripts/ angular.Modules.js #custom modules to be used across all apps .. resources/ views/ .. #landing page view Sub-App1/ app/ Http/ Controllers/ SubApp1Controller #sub-app1 specific API's .. public/ bower_components/ repo1/ #specific to sub-app1 ... resources/ AngularApp1 #SPA for sub-app1 views/ Sub-App2/ app/ ... 

And for routing, I would like something like:

 http://mylabs //login OR landing Page http://mylabs/subapp/route1/123someid 

What is the best way to achieve this in Laravel?

Is this structure good enough, scalable, manageable?

If this is not the best way to achieve this?

+5
source share
2 answers

For routing Laravel, you can use something like this:

 Route::group(['prefix' => 'subapp1'], function() { Route::get('route1/{id}', ' SubApp1Controller@show '); }); 

Your decision is likely to be a pain for future management. This creates complexity and duplication without buying you in terms of functionality. I would make sure that you have a really good reason for this, in addition to the fact that it’s easy for developers to work independently, because you can still have this with the following approach.

I would suggest using one Laravel application to handle all routes using a separate controller (or controllers) for each additional application. This will be easier to maintain and still allows developers to stay in their files so that they do not conflict with each other. The exception will be routes.php , but you can define routes up so that developers do not all edit it.

I prefer to keep Angular separate from Laravel by putting Angular code in a shared folder, but it depends on how much you plan to do with Blade vs. Angular It's hard to say without knowing more about your applications, but you can leave most of the work in Angular, and Laravel will just send the source page.

This avoids conflicts with Blade vs. Angular and supports disconnecting an Angular application from Laravel. But if you decide to keep Angular in Laravel views, be sure to handle it somehow. A few common solutions are to change the delimiters from the {{ }} or prefix Angular expressions with the @ symbol as follows: @{{ user.email }} to prevent Blade from being parsed.

Here you can lay out the directory structure:

 app/ Http/ Controllers/ AppBaseController.php # API that will be used across all apps SubApp1Controller.php # sub-app1 specific API's SubApp2Controller.php # sub-app2 specific API's ... public/ bower_components/ angular/ bootstrap/ scripts/ angular.Modules.js # custom modules to be used across all apps AngularApp1/ # SPA for sub-app1 AngularApp2/ # SPA for sub-app2 ... resources/ views/ ... # landing page view sub-app1/ ... # sub-app1 views sub-app2/ ... # sub-app2 views 
+6
source

I understand modules as an independent part of the application. And the application must be formed using different modules. Each module can have configuration and routing that can be overridden in the application configuration. This can be achieved with providers. As a file system structure, I recommend reading these two links about organizing your application in a modular way here and. Another thing is to use controllerAs and avoid using scope in the controller, as scope will disappear in future versions of angular. Another styleguide resource

0
source

Source: https://habr.com/ru/post/1216605/


All Articles