dev-master
9999999-devModules Provider for Laravel 5
MIT
The Requires
by Neil Herbert
laravel framework laravel 5 laravel modules neilherbertuk neil herbert
Modules Provider for Laravel 5
A package to add modules to a Laravel 5 application. This package allows you to separate out code for parts of your application into their own dedicated "modules" or folders, allowing all code related to a specific section or function of your application to be stored in one place., (*2)
Compatible with: - Laravel 5.4 - Laravel 5.5, (*3)
Currently supports: - Controllers - Migrations - Models - Routes, web and api - Service Providers - Views - Console Commands, (*4)
Currently not supported: - Database Seeding - Module Middleware, (*5)
This package will soon have commands to assist in making each of these., (*6)
An admin panel at domain.com/admin - all functionality related to the admin panel could be turned into a module and stored together in a single location., (*7)
Example Structure, (*8)
Admin - Admin/controllers - - Admin/controllers/AdminController.php - Admin/database - - Admin/database/migrations - - - Admin/database/migrations/Create_A_Table_Migrtion.php - Admin/models - - Admin/models/statistics.php - Admin/views - - Admin/views/dashboard.blade.php - Admin/web.php
This version has been tested with Laravel 5.4 and 5.5, other versions will be tested in the future., (*9)
$ composer require neilherbertuk/laravel-modules:dev-master
If you are using Laravel 5.4, you will need to register the service provider in your config/app.php
, (*10)
neilherbertuk\modules\ModuleServiceProvider::class,
If you are using Laravel 5.5 or up, Automatic Package Discovery should autoload the ModuleServiceProvider
, if this does not happen run the following commands from the root of your laravel project:, (*11)
$ composer dump-autoload $ php artisan package:discover
If you would like to make changes to the default configuration, publish the package's config file., (*12)
$ php artisan vendor:publish --provider="neilherbertuk\modules\ModuleServiceProvider" --tag=config
This will create a config/modules.php
file in your app that you can modify to set your configuration., (*13)
The package can be configured to work in several ways. By default the package will autoload modules under the app\Modules
folder., (*14)
In my opinion (correct me if I am wrong) auto-loading is great in development, but not recommended in production due to the expensive nature of finding each available module., (*15)
This is the default behaviour, but can be added to your .env
file, (*16)
MODULES_AUTOLOAD=true
Add the following to your .env
file, (*17)
MODULES_AUTOLOAD=false
Manual loading of modules will occur when Autoload is disabled.
Within your config/modules.php
file you will find a blank enabled
array. Simply add the name of each module you wish to manually load as a new entry. Each name is the name of the folder your module sits in., (*18)
'enabled' => [ 'Admin', 'Forum' ],
When using Autoloading, it is possible to disable certain modules. Within your config/modules.php
file is a blank disabled
array. Any modules listed here will not be loaded., (*19)
'disabled' => [ 'Admin' ],
To be completed., (*20)
The Laravel-Modules package comes with a handy console command to help build new modules. It's usage can be seen by running the following command:, (*21)
$ php artisan make:module
To create a new module, run the following command from the root of your Laravel project, (*22)
$ php artisan make:module --create ModuleName [--webroute | --apiroute]
This will create a new folder structure as shown in the example above within your app/Module
folder., (*23)
Unless an option is given, by default, the create command will also create a web routes file (web.php
).
The routes file generated by this will include a group prefix to help separate your module from other parts of your application., (*24)
If you would prefer to create an api route file (api.php
) add --apiroute
to the command., (*25)
$ php artisan make:module --create ModuleName --apiroute
If you would like to add both a web and api routes file, add both --webroute
and --apiroute
to the create command,
alternatively you can use these options without --create
if the module has already been created., (*26)
$ php artisan make:module --create ModuleName --apiroute --webroute
The module name will automatically be converted to lower case and used as a prefix for any routes file created. If you create a new module named "Dashboard", anything within the module will be available at domain.com/dashboard/, (*27)
You can create a new module controller using the --controller option, optionally you can also include --resource, (*28)
$ php artisan make:module ModuleName --controller NameOfController [--resource]
This will place a new controller into your app\Modules\ModuleName\Controllers
folder. By default this will create a plain controller.
If you would like to create a resource controller add --resource which will include all of the basic CRUD methods for you., (*29)
All files related to the module must belong to the same namespace. This is done automatically for you if you use the provided console commands., (*30)
namespace app\Modules\ModuleName\Controllers; namespace app\Modules\ModuleName\Models; namespace app\Modules\ModuleName\Migrations;
Please report any bugs by opening an issue on github., (*31)
Please email any security issues directly to neil@ea3.co.uk., (*32)
Modules Provider for Laravel 5
MIT
laravel framework laravel 5 laravel modules neilherbertuk neil herbert