Weave Code
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

Symfony Admin Bundle Laravel Package

alexander-a2/symfony-admin-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require alexander-a2/symfony-admin-bundle
    

    Register the bundle in config/bundles.php:

    return [
        // ...
        AlexanderA2\SymfonyAdminBundle\SymfonyAdminBundle::class => ['all' => true],
    ];
    
  2. Enable CRUD for an Entity Create a YAML config file (e.g., config/packages/symfony_admin.yaml):

    symfony_admin:
        resources:
            App\Entity\YourEntity:
                title: "Your Entity"
                list: [id, name, createdAt]
                show: [id, name, description]
                edit: [name, description]
    
  3. First Use Case Access /admin to see the auto-generated admin panel for YourEntity. No controller or template needed—just define the config.


Implementation Patterns

Workflow: Rapid CRUD Generation

  • Define Resources in Config Use YAML/XML/PHP to declare entities, fields, and actions:

    symfony_admin:
        resources:
            App\Entity\User:
                title: "Users"
                list: [id, email, roles]
                edit: [email, roles, isActive]
                actions:
                    - { name: "ban", label: "Ban User" }
    
    • Supports nested relations (e.g., list: [posts.title] for User entity).
  • Customize Field Types Override default form types via config:

    App\Entity\User:
        fields:
            email:
                type: "email"
            roles:
                type: "entity"
                options:
                    class: App\Entity\Role
    
  • Extend with Controllers For advanced logic, create a custom controller:

    // src/Controller/Admin/UserAdminController.php
    namespace App\Controller\Admin;
    use AlexanderA2\SymfonyAdminBundle\Controller\AbstractAdminController;
    
    class UserAdminController extends AbstractAdminController
    {
        public function banAction($id): Response
        {
            $user = $this->getEntityManager()->getRepository(User::class)->find($id);
            $user->setIsActive(false);
            $this->getEntityManager()->flush();
            return $this->redirectToRoute('admin_user_index');
        }
    }
    

    Link it in config:

    App\Entity\User:
        controller: App\Controller\Admin\UserAdminController
    

Integration Tips

  • Doctrine ORM Only Bundle assumes Doctrine ORM. For other databases, mock the EntityManager or extend the bundle.
  • KNP Menu Integration Auto-generates admin menu items via knp_menu:
    symfony_admin:
        menu:
            - { route: 'admin_user_index', label: 'Users' }
    
  • Twig Extensions Access admin helpers in templates:
    {{ admin.generate_list_link(entity) }}
    

Gotchas and Tips

Pitfalls

  1. PHP 8.3+ Requirement Ensure your project uses PHP ≥8.3. Downgrade may break type hints or attributes.

  2. Missing knp-menu-bundle If the admin menu doesn’t appear, install:

    composer require knplabs/knp-menu-bundle
    

    And configure it in config/packages/knp_menu.yaml.

  3. Field Overrides Not Applied Verify YAML indentation (2 spaces per level). Example:

    # Correct
    fields:
        name:
            type: "text"
            options:
                attr:
                    placeholder: "Enter name"
    
  4. Actions Not Triggering Ensure the action method exists in your custom controller and is listed in actions:

    actions:
        - { name: "ban", label: "Ban" }  # Must match method name
    

Debugging

  • Check Config Loading Dump the loaded config in a controller:

    use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
    public function debugConfig(ParameterBagInterface $params): Response
    {
        return new Response(print_r($params->get('symfony_admin'), true));
    }
    

    Route: /debug/config.

  • Enable Debug Mode Set APP_DEBUG=1 in .env to see detailed errors for missing entities or fields.

Extension Points

  1. Custom Field Types Create a service tagged as symfony_admin.field_type:

    services:
        App\FieldType\CustomType:
            tags:
                - { name: symfony_admin.field_type, alias: "custom" }
    

    Implement AlexanderA2\SymfonyAdminBundle\Form\FieldTypeInterface.

  2. Event Listeners Subscribe to admin events (e.g., pre_save, post_delete):

    use AlexanderA2\SymfonyAdminBundle\Event\AdminEvent;
    
    public function onPreSave(AdminEvent $event): void
    {
        $entity = $event->getEntity();
        $entity->setUpdatedAt(new \DateTime());
    }
    

    Tag the service:

    services:
        App\EventListener\AdminListener:
            tags:
                - { name: kernel.event_listener, event: symfony_admin.pre_save, method: onPreSave }
    
  3. Override Templates Copy templates from vendor/alexander-a2/symfony-admin-bundle/Resources/views/ to templates/admin/ to customize layouts or partials.

Pro Tips

  • Bulk Actions Enable via config:
    App\Entity\User:
        bulk_actions:
            - { name: "delete", label: "Delete Selected" }
    
  • Soft Deletes Add a isDeleted field and filter lists:
    App\Entity\User:
        list:
            - { field: "id", label: "ID" }
            - { field: "name", label: "Name" }
        filters:
            - { field: "isDeleted", operator: "!=", value: true }
    
  • Performance For large datasets, add paginator options:
    App\Entity\User:
        list:
            paginator:
                items_per_page: 50
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui