Generate boilerplate code for Laravel
Laravel package for generating Laravel Modules from a template.
PHP 8.2+
Laravel Modules package installed https://github.com/nWidart/laravel-modules
https://www.youtube.com/watch?v=BwYzfb9Fa8A&t=2s
You can install the package via composer:
composer require dcblogdev/laravel-module-generator
Publish both the config and stubs:
php artisan vendor:publish --provider="Dcblogdev\ModuleGenerator\ModuleGeneratorServiceProvider"
This will publish a module-generator.php config file
This contains:
'template' => [
'Breeze - Blade - CRUD Web & API' => 'stubs/module-generator/breeze-crud-full',
'Breeze - Blade - CRUD Web only' => 'stubs/module-generator/breeze-crud-web',
'Breeze - Blade - CRUD API only' => 'stubs/module-generator/breeze-crud-api'
],
'ignore_files' => ['module.json']
By default, the stubs will be located at stubs/module-generator you can add your paths by adding folders and updating the config file.
php artisan module:build
{module?} is the name of the module you want to create. If you don't provide a name you will be asked to enter one.
{template?} is the name of the template you want to use. If you don't provide a name you will be asked to enter one.
php artisan module:build Contacts "Breeze - CRUD API only"
Once a module has been created, enable it:
php artisan module:enable ModuleName
Then run:
composer dump-autoload
Create or update the stubs file. The filename and contents should have placeholders for example ModulesController will be replaced with your name + Controller. ie ContactsController when the command is executed.
These placeholders are replaced with the name provided when running php artisan module:build
Module = Module name ie Contacts
module = Module name in lowercase ie contacts
module_plural = Plural module name in lowercase ie demo becomes demos
Model = Model name ie Contact
model = Model name in lowercase ie contact
$name = 'PurchaseOrders')| Placeholder | Value |
|---|---|
| {Module} | PurchaseOrders |
| {Module } | Purchase Orders |
| {Module-} | Purchase-Orders |
| {Module_} | Purchase_Orders |
| {ModuleCamel} | purchaseOrders |
| {ModuleStudly} | PurchaseOrders |
| {ModuleTitle} | Purchase Orders |
| {module} | purchaseorders |
| {module } | purchase orders |
| {module-} | purchase-orders |
| {module_} | purchase_orders |
| {moduleCamel} | purchaseOrders |
| {moduleStudly} | PurchaseOrders |
| {modulePlural} | purchase orders |
| {module_plural} | purchase orders |
| {module_plural_snake} | purchase_orders |
| {module_plural_kebab} | purchase-orders |
| {module_title} | Purchase Orders |
$model = 'PurchaseOrder')| Placeholder | Value |
|---|---|
| {Model} | PurchaseOrder |
| {Model } | Purchase Order |
| {Model-} | Purchase-Order |
| {Model_} | Purchase_Order |
| {ModelCamel} | purchaseOrder |
| {ModelStudly} | PurchaseOrder |
| {ModelTitle} | Purchase Order |
| {model} | purchaseorder |
| {model } | purchase order |
| {model-} | purchase-order |
| {model_} | purchase_order |
| {modelCamel} | purchaseOrder |
| {modelStudly} | PurchaseOrder |
| {model_plural} | purchase orders |
| {model_plural_snake} | purchase_orders |
| {model_plural_kebab} | purchase-orders |
| {model_title} | Purchase Order |