A simple code generator for Laravel projects to streamline development.
-
Install via Composer
composer require lucasandre-dev/laravel-code-generator
-
Publish the Service Provider Register the service provider in your
config/app.php
file:'providers' => [ // Other Service Providers... LucasandreDev\LaravelCodeGenerator\Providers\CodeGeneratorProvider::class, ],
Note:
For Laravel versions <= 10: Registering Providers in Laravel 10
For Laravel versions >= 11: Registering Providers in Laravel 11 -
Publish Configuration and Mockups
- Config File:
php artisan vendor:publish --tag=templates-code-generator-config
- Mockups:
php artisan vendor:publish --tag=templates-code-generator-mockups
- Config File:
-
Add Filesystem Configuration Add the following configuration to
config/filesystems.php
:'templates' => [ 'driver' => 'local', 'root' => base_path(), 'throw' => true, ],
-
Configure Template Generator Modify the configuration in
config/templates-code-generator.php
to suit your needs. -
Run Code Generation Command Execute the following command to generate code:
php artisan code:generate
Note:
When running the command, you'll be prompted to provide an entity name and a template name.
- disk: Disk used for storing generated files.
- base_destination: Base path for all generated files.
- template_default: Default template used by the command to generate code.
- templates: List of templates with operations, template locations, and final dynamic destinations.
Replacements:
%EntityNamespace%
: Recommended usage in the mockups namespace.%PascalCase%
: The entity name in PascalCase format.%camelCase%
: The entity name in camelCase format.
Options:
--force
: Force overwrite of existing files (use with caution).
Prompts:
- Entity: Name of the entity to be created. Allows subpaths (e.g.,
Path1/Path2/EntityName
). - Template: Select a template number from the options suggested in the terminal.