Modularize Your Laravel Application With the Modular Package
Last updated on by Paul Redmond
The InterNACHI/modular package is a module system for Laravel applications for features you want to build modularly. This package provides convenience commands and tools that aid you in creating modules within your Laravel application.
Once you install this package in your Laravel application, creating a module is as easy as running the following Artisan command, which will walk you through the setup process:
php artisan make:module teams # Use existing Laravel commands with a new `--module` flagphp artisan make:controller ExampleController --module=teams
It has the following features that make breaking up your code into modules easy yet still keeping Laravel conventions:
- Create new Laravel modules via an Artisan command
- Module autoloading via Composer
- Laravel provider and alias discovery via Composer
- Customizable configuration/conventions around modules
- Commands are auto-registered with Artisan
- The migrator automatically runs migrations
- Model policies are auto-discovered
- Blade components are auto-discovered
- Event listeners are auto-discovered
- Artisan
make:*
commands for your modules - And more…
This package doesn’t prescribe what code belongs in a module vs. app/
code but does allow you to draw on Laravel conventions even as you build separate modules. You can easily extract module code into a separate Laravel package. I like this approach as it lets you quickly create reusable module code without fully committing to a separate package.
Learn More
This package is available on GitHub at InterNACHI/modular, including installation instructions and documentation in the project’s README. If you’re more of a visual person, package author Chris Morrell has a walkthrough video that covers how to use this package and the thought process behind it.