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

Crud Bundle Laravel Package

ecommit/crud-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle via Composer:

    composer require ecommit/crud-bundle
    

    Enable the bundle in config/bundles.php:

    Ecommit\CrudBundle\EcommitCrudBundle::class => ['all' => true],
    
  2. First Use Case: Basic CRUD Controller Generate a scaffolded controller for an Article entity:

    php bin/console make:crud Article
    

    This creates a controller with basic CRUD actions (index, create, edit, show, delete) in src/Controller/ArticleController.php.

  3. Where to Look First

    • Documentation: Start with the French docs (use a translator if needed).
    • Generated Code: Inspect the auto-generated controller to understand the structure.
    • Configuration: Check config/packages/ecommit_crud.yaml for default settings.

Implementation Patterns

Common Workflows

  1. Customizing CRUD Actions Override methods in the generated controller to add logic:

    // src/Controller/ArticleController.php
    public function edit(Request $request, Article $article, EntityManagerInterface $em)
    {
        // Custom logic before edit
        $form = $this->createForm(ArticleType::class, $article);
        // ...
    }
    
  2. Adding Fields to Forms Extend the auto-generated ArticleType form class:

    // src/Form/ArticleType.php
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('custom_field', TextType::class);
    }
    
  3. Integration with Existing Projects

    • Symfony Forms: Leverage Symfony’s form system for validation and rendering.
    • Twig Templates: Override templates in templates/EcommitCrudBundle/ to customize UI.
    • Doctrine: Works seamlessly with Doctrine entities (ensure proper use statements).
  4. API-First Approach Use the bundle’s built-in serialization (JMS Serializer or Symfony Serializer) for API responses:

    # config/packages/ecommit_crud.yaml
    ecommit_crud:
        serialization: true
    
  5. Bulk Actions Add bulk delete/edit functionality by extending the controller:

    public function bulkDelete(Request $request)
    {
        $ids = $request->request->get('ids');
        // Logic to delete multiple records
    }
    

Gotchas and Tips

Pitfalls

  1. French Documentation

    • Key terms may not translate directly (e.g., "CRUD" is assumed knowledge).
    • Use context clues or translate critical sections (e.g., "Générer un contrôleur" = "Generate a controller").
  2. Auto-Generated Code Overrides

    • Avoid editing auto-generated files directly. Instead, extend them (e.g., create ArticleController.php in src/Controller/ and override methods).
    • Example:
      // src/Controller/ArticleController.php (extends auto-generated)
      class ArticleController extends AbstractCrudController
      {
          public function configureFields(string $action): iterable
          {
              return parent::configureFields($action) + [
                  'custom_field' => 'text',
              ];
          }
      }
      
  3. Entity Requirements

    • Entities must have an id field (auto-incremented primary key).
    • Soft deletes require the SoftDeletable trait or a deletedAt column.
  4. Routing Conflicts

    • Default routes may clash with existing ones. Customize routes in config/routes.yaml:
      ecommit_crud_article:
          resource: '@EcommitCrudBundle/Resources/config/routing/article.yaml'
          prefix: '/admin'
      
  5. JavaScript Dependencies

    • The bundle may rely on Stimulus or other JS libraries. Ensure webpack.config.js includes:
      Encore
          .enableStimulus()
          .addEntry('app', './assets/app.js');
      

Debugging Tips

  1. Check the debug:config Command Verify bundle settings:

    php bin/console debug:config ecommit_crud
    
  2. Enable Profiler Use Symfony’s profiler to inspect form submissions or entity changes:

    // config/packages/dev/debug.yaml
    framework:
        profiler: { only_exceptions: false }
    
  3. Log Form Errors Add this to your controller to debug form validation:

    public function create(Request $request)
    {
        $form = $this->createForm(ArticleType::class);
        $form->handleRequest($request);
    
        if ($form->isSubmitted() && !$form->isValid()) {
            \Log::error('Form errors:', $form->getErrors(true));
        }
    }
    

Extension Points

  1. Custom Actions Add new actions by extending the controller:

    public function publish(Article $article)
    {
        $article->setIsPublished(true);
        $this->getDoctrine()->getManager()->flush();
        return $this->redirectToRoute('article_index');
    }
    
  2. Event Listeners Subscribe to bundle events (e.g., crud.pre_save) in config/services.yaml:

    services:
        App\EventListener\CrudListener:
            tags:
                - { name: kernel.event_listener, event: crud.pre_save, method: onPreSave }
    
  3. Template Overrides Copy the default template from vendor/ecommit/crud-bundle/templates/ to templates/EcommitCrudBundle/ and modify.

  4. Translation Extend translations in translations/messages.fr.yaml or messages.en.yaml:

    # messages.en.yaml
    crud:
        article:
            actions:
                publish: "Publish Article"
    
  5. Testing Use the bundle’s test utilities in PHPUnit:

    public function testCrudActions()
    {
        $client = static::createClient();
        $crawler = $client->request('GET', '/article');
        $this->assertSelectorTextContains('h1', 'Articles');
    }
    

```markdown
---
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.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc