Laravel Modular Boilerplate
A Laravel 5.* boilerplate for creating modular applications.
An article explaining how it was created how can you use it can be found through this blog post Creating a Modular Application in Laravel 5.1
Please follow the below steps to setup the application
- Clone the repository
git clone http://github.com/kamranahmedse/laravel-modular-boilerplate
- Install dependencies via composer
- Create a
.envfile, maybe by duplication
.env.examplewhich is already there.
- Generate the key:
php artisan key:generate
- The application is ready. A dummy module called
ModuleOnehas already been added to give you an idea about how it works. The module has some routes, a controller and a dummy model as well. Considering that you are serving the repository via
php artisan serveat port
8000you can access the dummy routes placed in
Adding your Modules
Create a directory with your module name e.g.
app/Modulesdirectory. Inside this directory create a file called
routes.phpfor the routes and create the directories
Viewsfor your controllers, models and views respectively.
Open up the file
config/module.php. This is the file where you will be registring your modules. Add your module name in the
modulesarray like this:
return [ 'modules' => [ 'ModuleOne', 'MyAwesomeModule' ] ];
app\Modules\MyAwesomeModule\Controllersdirectory, create your controllers with the namespace set to
App\Modules\MyAwesomeModule\Controllers. In the same way, create the models inside
app\Modules\MyAwesomeModule\Modelsdirectory with the namespace set to
App\Modules\MyAwesomeModule\Models. And create the view files in the
app\Modules\MyAwesomeModule\Viewsdirectory. Everything i.e. Controllers, models and views in this module work the same, however while using views you will have to specify your views like
MyAwesomeModule::viewNamei.e. you will have to prepend the modulename with the resolution to the start of how you normally access a view.