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

Crudit Bundle Laravel Package

2lenet/crudit-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require 2lenet/crudit-bundle
    npm install bootstrap@5 sass sass-loader @fortawesome/fontawesome-free easymde --save
    
  2. Enable the Bundle: Add to config/bundles.php:

    return [
        // ...
        Lle\CruditBundle\LleCruditBundle::class => ['all' => true],
    ];
    
  3. Basic Twig Integration: Extend the provided layout in your base template (templates/base.html.twig):

    {% extends '@LleCrudit/layout/sb_admin/layout.html.twig' %}
    
    {% block stylesheets %}
        {{ encore_entry_link_tags('app') }}
    {% endblock %}
    
    {% block javascripts %}
        {{ parent() }}
        {{ encore_entry_script_tags('app') }}
    {% endblock %}
    
  4. First CRUD: Follow the CRUD doc to scaffold a basic CRUD interface for an entity (e.g., App\Entity\Post):

    php bin/console lle:crudit:generate Post
    

First Use Case

Generate a CRUD for a Product entity and customize the list view to display name, price, and createdAt:

php bin/console lle:crudit:generate Product

Then override the list template in templates/LleCrudit/Product/list.html.twig:

{% extends '@LleCrudit/Product/list.html.twig' %}

{% block table_headers %}
    {{ parent() }}
    <th>Price</th>
{% endblock %}

{% block table_rows %}
    {{ parent() }}
    <td>{{ product.price }}</td>
{% endblock %}

Implementation Patterns

Workflows

  1. Scaffolding: Use the lle:crudit:generate command to create CRUD interfaces for entities:

    php bin/console lle:crudit:generate User --fields=name,email,roles --list=name,email,createdAt
    
    • --fields: Specify fields to include in the form.
    • --list: Define columns for the list view.
  2. Customization: Override default templates in templates/LleCrudit/[EntityName]/:

    • list.html.twig: Modify the table structure.
    • edit.html.twig: Customize the form fields.
    • show.html.twig: Adjust the detail view.
  3. Field Types: Leverage built-in field types (e.g., text, number, boolean, association) or create custom ones by extending Lle\CruditBundle\Form\Type\AbstractType.

  4. Filters: Add filters to list views using the filters option in the CRUD configuration (see Filters doc):

    # config/packages/lle_crudit.yaml
    lle_crudit:
        cruds:
            App\Entity\Product:
                list:
                    filters:
                        - { name: 'name', type: 'text' }
                        - { name: 'price', type: 'number' }
    
  5. Menus: Integrate CRUDs into the sidebar menu via the menu configuration:

    lle_crudit:
        menu:
            - { route: 'lle_crudit_product_list', label: 'Products', icon: 'box' }
    
  6. Bricks: Reuse UI components (e.g., cards, modals) by creating custom bricks (see Brick doc):

    {% render_brick 'product_card', { product: product } %}
    

Integration Tips

  • Webpack Encore: Ensure app.js imports Crudit’s SCSS after your custom styles:

    // assets/js/app.js
    import '../styles/app.scss';
    
    // assets/styles/app.scss
    @import '../../vendor/le/crudit-bundle/assets/sb-admin/css/app.scss';
    
  • Security: Protect CRUD routes with Symfony’s security system (e.g., @IsGranted("ROLE_ADMIN") in controllers).

  • Validation: Extend entity validation or use Crudit’s built-in validation by configuring field rules in the CRUD YAML:

    lle_crudit:
        cruds:
            App\Entity\Product:
                fields:
                    price:
                        validation: { notBlank: true, min: 0 }
    
  • API Integration: Use Crudit for admin interfaces while keeping API endpoints separate (e.g., via Symfony’s ApiPlatform or custom controllers).


Gotchas and Tips

Pitfalls

  1. SCSS Order:

    • Issue: Crudit’s SCSS may override your custom styles if imported after your styles.
    • Fix: Import Crudit’s SCSS last in app.scss (as shown in the README).
  2. Webpack Encore Conflicts:

    • Issue: Duplicate jQuery or Bootstrap instances if not configured properly.
    • Fix: Merge Encore configs or use webpack.config.js to resolve dependencies:
      // webpack.config.js
      Encore.enableSingleRuntimeChunk()
          .cleanupOutputBeforeBuild()
          .configureBabel((config) => {
              config.plugins.push('@babel/plugin-proposal-class-properties');
          })
          .configureLoaderRule('sass', (rule) => {
              rule.use.push({
                  loader: 'sass-loader',
                  options: { implementation: require('sass') }
              });
          });
      
  3. Template Overrides:

    • Issue: Overriding templates may break if the base template structure changes.
    • Fix: Use {% block %} inheritance carefully. For example, to add a column:
      {% block table_rows %}
          {{ parent() }} {# Renders default rows #}
          <td>{{ product.customField }}</td>
      {% endblock %}
      
  4. Entity Changes:

    • Issue: Regenerating a CRUD after schema changes may not update templates.
    • Fix: Delete the templates/LleCrudit/[EntityName]/ directory and regenerate:
      rm -rf templates/LleCrudit/Product/
      php bin/console lle:crudit:generate Product
      
  5. Performance:

    • Issue: Large datasets may slow down the list view.
    • Fix: Use Doctrine pagination or add a limit option in the CRUD config:
      lle_crudit:
          cruds:
              App\Entity\Product:
                  list:
                      pagination: 20
      

Debugging

  1. Console Commands: List available CRUDs to verify configuration:

    php bin/console lle:crudit:list
    
  2. Template Debugging: Enable Twig debug mode in .env:

    APP_DEBUG=1
    

    Use {{ dump(_context) }} in templates to inspect variables.

  3. JavaScript Errors: Check the browser console for errors related to:

    • Missing jQuery or Bootstrap.
    • Conflicting SCSS variables (e.g., $primary).
    • Fix: Override variables in app.scss:
      $primary: #your-color !default;
      @import '../../vendor/le/crudit-bundle/assets/sb-admin/css/app.scss';
      

Extension Points

  1. Custom Field Types: Create reusable field types by extending AbstractType:

    // src/Form/Type/CustomFieldType.php
    namespace App\Form\Type;
    
    use Lle\CruditBundle\Form\Type\AbstractType;
    
    class CustomFieldType extends AbstractType {
        public function buildForm(FormBuilderInterface $builder, array $options) {
            $builder->add('custom_field', TextType::class);
        }
    
        public function configureOptions(OptionsResolver $resolver) {
            $resolver->setDefaults([
                'label' => 'Custom Field',
            ]);
        }
    }
    

    Register in config/packages/lle_crudit.yaml:

    lle_crudit:
        field_types:
            custom: App\Form\Type\CustomFieldType
    
  2. Event Listeners: Hook into Crudit events (e.g., CruditEvent::PRE_LIST) to modify queries or data:

    // src/EventListener/CruditListener.php
    namespace App\EventListener;
    
    use Lle\CruditBundle\Event\CruditEvent;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    class CruditListener implements EventSubscriberInterface {
        public static function getSubscribedEvents() {
            return [
                CruditEvent::PRE_LIST => 'onPreList',
            ];
        }
    
        public function onPreList(CruditEvent $event) {
            $event->getQueryBuilder()->andWhere('e.active = :active')
                ->setParameter('active', true);
        }
    }
    
  3. Dynamic Routes: Override routing for CRUD actions in config/routes.yaml:

    lle
    
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