Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Admingenerator Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require nitra/admingenerator-bundle
    

    Add to config/bundles.php:

    Nitra\AdminGeneratorBundle\NitraAdminGeneratorBundle::class => ['all' => true],
    
  2. 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
    
  3. 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
    

Implementation Patterns

Workflow: Iterative Admin Panel Development

  1. 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' }
    
  2. 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.

  3. Integrate with Existing Code

    • Services: Inject the generator service (nitra_admin_generator.generator) to dynamically generate configs or entities.
    • Events: Listen to 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 }
      
  4. 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' } }
    

Gotchas and Tips

Pitfalls

  1. YAML Syntax Errors

    • Issue: Silent failures or partial generation due to invalid YAML.
    • Fix: Validate YAML with yaml.lint or use Symfony’s Debug/Yaml component:
      php bin/console debug:config nitra_admin_generator
      
  2. Caching Issues

    • Issue: Changes to YAML/configs not reflecting in the admin panel.
    • Fix: Clear the cache after updates:
      php bin/console cache:clear
      
    • Tip: Use debug:config to verify loaded configs.
  3. Entity Metadata Conflicts

    • Issue: Generator fails if entity metadata (e.g., orm.xml) conflicts with YAML definitions.
    • Fix: Explicitly define fields in YAML to override defaults or use @ORM\* annotations in your entity.
  4. Twig Template Overrides

    • Issue: Overridden templates not being picked up.
    • Fix: Ensure the override path follows Symfony’s template hierarchy:
      your_bundle/Resources/views/NitraAdminGeneratorBundle/Controller/YourEntity/list.html.twig
      

Debugging Tips

  • 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 }
    

Extension Points

  1. Custom Field Types Extend Nitra\AdminGeneratorBundle\Field\AbstractFieldType to create reusable field types (e.g., for nested forms or custom widgets).

  2. 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")' }
    
  3. 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.

  4. 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%']
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect