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

My Maker Bundle Laravel Package

aldaflux/my-maker-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require aldaflux/my-maker-bundle
    

    Ensure MyMakerBundle is enabled in config/bundles.php.

  2. Configuration: Publish the default config:

    php bin/console config:dump-reference aldaflux_mymaker > config/packages/aldaflux_mymaker.yaml
    

    Customize aldaflux_mymaker.yaml (e.g., adjust folder.controller, route.path_prefix).

  3. First Use Case: Generate a frontoffice CRUD for a User entity:

    php bin/console make:front:show User
    
    • Creates a UserController in src/Controller/Frontoffice/ and Twig templates in templates/frontoffice/user/.
    • Access the endpoint at /user/.

    Generate an admin CRUD with a voter:

    php bin/console make:crud:admin User --with-voter
    
    • Creates a full CRUD stack (controller, form type, Twig templates) in BackOffice/ namespace.
    • Access the admin panel at /admin/user/.

Implementation Patterns

Workflows

  1. Frontoffice Generation:

    • Use make:front:show for read-only listings (e.g., public user profiles).
    • Extend templates in templates/frontoffice/ to override defaults.
    • Example: Customize index.html.twig to add pagination or filters.
  2. Admin CRUD Generation:

    • Use make:crud:admin for full CRUD operations (create, read, update, delete).
    • --with-voter adds a security voter (e.g., UserVoter in src/Security/Voter/).
    • Example: Generate a Product CRUD with validation:
      php bin/console make:crud:admin Product --validation
      
  3. Integration with Existing Code:

    • Controllers: Extend generated controllers to add custom logic:
      // src/Controller/BackOffice/UserController.php
      public function customizeShow(User $user)
      {
          $this->addFlash('success', 'Custom logic executed!');
          return $this->renderShow($user);
      }
      
    • Forms: Extend UserType to add fields or constraints:
      // src/Form/UserType.php
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder->add('role', EntityType::class, ['class' => Role::class]);
      }
      
    • Routes: Override routes in config/routes.yaml:
      admin_user:
          resource: '@BackOffice/UserController'
          type: 'annotation'
          prefix: '/custom-admin-path'
      
  4. Template Inheritance:

    • Create a base template (e.g., templates/backoffice/base.html.twig) and extend it in generated templates:
      {# templates/backoffice/user/show.html.twig #}
      {% extends 'backoffice/base.html.twig' %}
      {% block body %}
          {{ include('backoffice/user/_show.html.twig') }}
      {% endblock %}
      
  5. Entity-Specific Customization:

    • Use --fields to specify only required fields:
      php bin/console make:crud:admin Post --fields="title:text,content:textarea,published:boolean"
      

Gotchas and Tips

Pitfalls

  1. Namespace Conflicts:

    • Ensure BackOffice and Frontoffice folders exist in src/Controller/ or configure custom paths in aldaflux_mymaker.yaml.
    • Fix: Create the folders manually or adjust the config:
      my_maker:
          backoffice:
              folder:
                  controller: App\Controller\Admin  # Custom namespace
      
  2. Twig Template Overrides:

    • Generated templates assume a default structure. Overriding them may break inheritance.
    • Tip: Use {% extends %} and {% block %} to modify templates safely.
  3. Route Prefix Collisions:

    • Default admin_ prefix may conflict with existing routes (e.g., Symfony’s admin dashboard).
    • Fix: Change route.path_prefix in config:
      my_maker:
          backoffice:
              route:
                  path_prefix: 'backend'
      
  4. Entity Not Found:

    • The bundle assumes the entity exists. If User doesn’t exist, the command fails silently.
    • Tip: Generate the entity first:
      php bin/console make:entity User
      
  5. Security Voter Placement:

    • --with-voter creates a voter in src/Security/Voter/, but the bundle doesn’t register it automatically.
    • Fix: Manually add the voter to config/packages/security.yaml:
      security:
          access_control:
              - { path: ^/admin/user, roles: ROLE_USER }
      
  6. Form Type Conflicts:

    • If UserType already exists, the command may overwrite it or fail.
    • Tip: Use --no-form to skip form generation or merge manually.

Debugging

  1. Command Output:

    • Check the full command output for errors (e.g., missing dependencies like sylius/resource-bundle).
  2. Generated Files:

    • Inspect generated files (e.g., UserController.php) for syntax errors or missing logic.
  3. Configuration Validation:

    • Validate YAML config:
      php bin/console debug:config aldaflux_mymaker
      

Extension Points

  1. Custom Templates:

    • Override default templates by placing them in templates/backoffice/ or templates/frontoffice/ before running the command.
  2. Event Subscribers:

    • Listen to maker.generate events to modify generation logic (requires Symfony EventDispatcher).
  3. Dynamic Field Mapping:

    • Extend the bundle by adding custom field types or validation rules via a service:
      # config/services.yaml
      services:
          App\Maker\CustomFieldType:
              tags: [aldaflux_mymaker.field_type]
      
  4. Multi-Environment Configs:

    • Use environment-specific configs (e.g., aldaflux_mymaker.dev.yaml) for development vs. production paths.
  5. Testing:

    • Test generated CRUDs with:
      php bin/console make:test UserCrudTest
      
    • Mock dependencies in tests/Controller/BackOffice/UserControllerTest.php.
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware