cedriclombardot/twig-generator
TwigGenerator is a PHP code generator powered by Twig templates. Create builders and reusable template layouts to generate PHP classes and features cleanly and extensibly, using a Generator to render templates into output files.
macro/trait systems).php artisan generate:model command for CLI-driven workflows.Storage::put() with checksums) or integrate with Laravel Mix/Vite for asset-like generation.post-update-cmd in composer.json) with opt-in runtime support.make:resource) or runtime codegen (e.g., dynamic API contracts)?Generator as a singleton with bound dependencies (e.g., Storage, Filesystem).generate:model) with options for:
--templates=path/to/templates).--output=app/Generated).--force).generating/generated events for hooks (e.g., logging, notifications).HasSoftDeletes).ApiResource classes with custom fields.UserRepository, DTOs) with generated classes.@foreach → {% for %}), but some (e.g., @stack) may require workarounds.@auth checks).App/Generated/).composer require cedriclombardot/twig-generator.resources/templates/ directory with:
_base/class.php.twig).methods/crud.php.twig).laravel_namespace()).BaseBuilder for each generation type (e.g., ModelBuilder, PolicyBuilder).Config, Filesystem) via constructor.Generator in a service provider with default templates/variables.$generator->setTemplateDirs([resource_path('templates')]);
$generator->setVariables([
'namespace' => 'App\\Generated',
'useStatements' => ['Illuminate\Support\Facades\Log'],
]);
app/Console/Commands/GenerateCommand.php to expose CLI access.$generator->addBuilder(new ModelBuilder($request->input()));
$generator->writeOnDisk(app_path('Generated'));
composer post-update-cmd script to regenerate critical classes on deploy."scripts": {
"post-update-cmd": [
"php artisan generate:model --force"
]
}
twig-lint).composer.json (e.g., ^3.4 for Twig).templates/models/_base.php.twig).setVariable() options).How can I help you explore Laravel packages today?