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

Symfony CruditBundle for building CRUD back offices with SB Admin layout. Provides configurable controllers, datasources and filtersets, plus list views with pagination/sorting, actions, grouping, batch ops, export (CSV/Excel), markdown, workflows and more.

View on GitHub
Deep Wiki
Context7
## Getting Started

### Minimal Setup
1. **Installation**:
   ```bash
   composer require 2lenet/crudit-bundle
   npm install bootstrap@5 sass sass-loader @fortawesome/fontawesome-free easymde --save
  1. Enable the Bundle: Add to config/bundles.php:

    return [
        // ...
        Lle\CruditBundle\LleCruditBundle::class => ['all' => true],
    ];
    
  2. 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 %}
    
  3. 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. Conditional UI Elements: New in 1.18.4: Hide bricks, tabs, or actions dynamically based on the request context (e.g., user role, request type). Configure in YAML:

    # config/packages/lle_crudit.yaml
    lle_crudit:
        cruds:
            App\Entity\Product:
                bricks:
                    - { name: 'product_details', hidden: 'request.get('_route') == "api_products_show"' }
                tabs:
                    - { name: 'advanced', hidden: 'not user.hasRole("ROLE_ADMIN")' }
                actions:
                    - { name: 'delete', hidden: 'not is_granted("DELETE", product)' }
    
  3. 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.
  4. Field Types: Leverage built-in field types (e.g., text, number, boolean, association) or create custom ones by extending Lle\CruditBundle\Form\Type\AbstractType.

  5. 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' }
    
  6. Menus: Integrate CRUDs into the sidebar menu via the menu configuration:

    lle_crudit:
        menu:
            - { route: 'lle_crudit_product_list', label: 'Products', icon: 'box' }
    
  7. Bricks: Reuse UI components (e.g., cards, modals) and conditionally hide them:

    {% render_brick 'product_card', { product: product, hidden: 'not user.hasRole("ROLE_EDITOR")' } %}
    

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) or use the new hidden configuration for dynamic visibility.

  • 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). Leverage the hidden feature to exclude UI elements from API requests:

    lle_crudit:
        cruds:
            App\Entity\Product:
                bricks:
                    - { name: 'admin_actions', hidden: 'request.isXmlHttpRequest()' }
    

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.
  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
      
  6. Conditional Logic Errors:

    • Issue: Incorrect hidden expressions in YAML may cause runtime errors.
    • Fix: Test expressions in Twig first (e.g., {% if request.get('_route') == "api_products_show" %}) before applying them to YAML.

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';
      
  4. Conditional UI Debugging:

    • Issue: Bricks/tabs/actions not hiding as expected.
    • Fix: Add debug output in Twig to verify conditions:
      {% if not brick.hidden %}
          {% render_brick 'product_card', { product: product } %}
      {% else %}
          {# Debug: {{ dump(brick.hidden) }} #}
      {% endif %}
      

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 build
    
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