nitra/admingenerator-bundle
Laravel/PHP admin generator bundle for rapidly building admin panels and CRUD back offices. Provides scaffolding, code generation, and configurable resources to manage models, forms, lists, filters, and actions with minimal manual coding.
Installation
composer require nitra/admingenerator-bundle
Add to config/bundles.php:
Nitra\AdminGeneratorBundle\NitraAdminGeneratorBundle::class => ['all' => true],
Basic Configuration
Create a YAML config file (e.g., config/admin_generator.yml):
admin_generator:
generation_doctrine_orm: true
generation_doctrine_odm: false
generation_entities: true
generation_forms: true
generation_filters: true
generation_repositories: true
generation_controllers: true
generation_twig_templates: true
generation_routes: true
generation_menu: true
First Use Case: Generate a CRUD for an Entity
Define a YAML config for your entity (e.g., config/admin_generator/YourEntity.yml):
Your\Bundle\Entity\YourEntity:
icon: '<i class="fa fa-user"></i>'
list:
fields:
- { name: id, type: number }
- { name: name, type: string }
form:
fields:
- { name: name, type: text }
filter:
fields:
- { name: name, type: string }
Run the generator:
php bin/console nitra:admin-generator:generate
Define YAML Configs
Start with minimal YAML for an entity (e.g., YourEntity.yml). Gradually add fields, filters, and customizations.
Example for nested relations:
Your\Entity\Post:
list:
fields:
- { name: title, type: string }
- { name: author, type: entity, relation: author }
- { name: commentsCount, type: number, label: 'Comments' }
Customize Twig Templates Override default templates by copying them from:
vendor/nitra/admingenerator-bundle/Resources/views/
to:
your_bundle/Resources/views/NitraAdminGeneratorBundle/
Example: Override list.html.twig to add custom buttons.
Integrate with Existing Code
nitra_admin_generator.generator) to dynamically generate configs or entities.nitra.admin_generator.generate events to hook into the generation process.
// src/EventListener/CustomGeneratorListener.php
public function onGenerate(EntityGeneratorEvent $event) {
$event->addTemplatePath('custom_path');
}
Register in services.yml:
services:
your_bundle.listener.custom_generator:
tags:
- { name: kernel.event_listener, event: nitra.admin_generator.generate, method: onGenerate }
Dynamic Field Types
Extend field types by creating custom Twig extensions or overriding the field_type logic in your YAML:
Your\Entity\Product:
form:
fields:
- { name: price, type: custom_price, options: { currency: 'USD' } }
YAML Syntax Errors
yaml.lint or use Symfony’s Debug/Yaml component:
php bin/console debug:config nitra_admin_generator
Caching Issues
php bin/console cache:clear
debug:config to verify loaded configs.Entity Metadata Conflicts
orm.xml) conflicts with YAML definitions.@ORM\* annotations in your entity.Twig Template Overrides
your_bundle/Resources/views/NitraAdminGeneratorBundle/Controller/YourEntity/list.html.twig
Log Generation Steps:
Enable debug mode in config/packages/dev/nitra_admin_generator.yaml:
nitra_admin_generator:
debug: true
Check logs at var/log/dev.log for generation details.
Dry Run:
Use --dry-run to preview changes without generating files:
php bin/console nitra:admin-generator:generate --dry-run
Field-Specific Debugging:
Add debug: true to a field in YAML to log its rendering:
Your\Entity\Task:
form:
fields:
- { name: dueDate, type: date, debug: true }
Custom Field Types
Extend Nitra\AdminGeneratorBundle\Field\AbstractFieldType to create reusable field types (e.g., for nested forms or custom widgets).
Dynamic Menu Items
Use the menu section in YAML to conditionally generate menu items:
Your\Entity\Order:
menu:
- { label: 'Active Orders', route: 'admin_order_list', condition: '@security.authorization_checker.isGranted("ROLE_ADMIN")' }
Post-Generation Hooks
Implement Nitra\AdminGeneratorBundle\Generator\PostGeneratorInterface to run logic after generation (e.g., populate fixtures or run migrations):
public function postGenerate(GenerationContext $context) {
$this->fixtureLoader->load('YourBundle:fixtures/order.yml');
}
Register as a service with the nitra_admin_generator.post_generator tag.
Multi-Tenant Support Dynamically load YAML configs based on tenant:
# config/packages/prod/nitra_admin_generator.yaml
nitra_admin_generator:
config_paths: ['%kernel.project_dir%/config/admin_generator/tenant_%tenant_id%']
How can I help you explore Laravel packages today?