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

Ctrl Rad Bundle Laravel Package

ctrl-f5/ctrl-rad-bundle

Symfony bundle to get apps running fast: SB Admin 2 layout with configurable sidebar/topbar/breadcrumbs, Twig extensions for Bootstrap UI, template overrides, configurable CRUD (index/edit) with grid, pagination and filters, plus an EntityService layer and TableView.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup in Laravel (Symfony Bundle Adaptation)

Since ctrl-rad-bundle is a Symfony bundle, Laravel developers must first bridge it using Symfony Bridge (symfony/console, symfony/http-kernel) or Laravel Symfony Integration (e.g., spatie/laravel-symfony-support). Install via Composer:

composer require ctrl-f5/ctrl-rad-bundle symfony/console symfony/http-kernel

First Use Case: Scaffold a CRUD Layout

  1. Register the Bundle (in config/app.php for Laravel 5.x or config/bundles.php for Laravel 8+ with Symfony integration):

    'providers' => [
        // ...
        CtrlRadBundle\CtrlRadBundle::class,
    ],
    
  2. Publish Assets (Bower for SB Admin 2):

    php artisan vendor:publish --provider="CtrlRadBundle\CtrlRadBundle\CtrlRadBundle" --tag=assets
    npm install  # Install Bower dependencies (if using Laravel Mix)
    
  3. Generate a Basic CRUD Controller: Use the EntityService layer to abstract Doctrine calls. Example:

    // src/Service/PostService.php
    namespace App\Service;
    use CtrlRadBundle\Service\EntityService;
    
    class PostService extends EntityService {
        protected $entityClass = 'App\Entity\Post';
        protected $repositoryMethod = 'findAll'; // Optional: Override default repo method
    }
    
  4. Create a Controller leveraging the TableView:

    // src/Controller/PostController.php
    use CtrlRadBundle\Controller\CrudController;
    use App\Service\PostService;
    
    class PostController extends CrudController {
        protected $service;
        public function __construct(PostService $service) {
            $this->service = $service;
        }
        public function indexAction() {
            $tableView = $this->service->createTableView();
            $tableView->addColumn('title', 'Title');
            $table->addRowAction('edit', 'Edit', ['route' => 'edit_post']);
            return $this->render('CtrlRadBundle:Crud:index.html.twig', ['tableView' => $tableView]);
        }
    }
    
  5. Route the Controller:

    // routes/web.php
    use App\Controller\PostController;
    Route::resource('posts', PostController::class);
    
  6. Override Layout Blocks (e.g., sidebar): Create a custom template at resources/views/layouts/custom.html.twig:

    {% extends 'CtrlRadBundle::layout.html.twig' %}
    {% block sidebar %}
        {{ parent() }}
        <div class="sidebar-box">Custom Content</div>
    {% endblock %}
    

Implementation Patterns

1. Layout Customization Workflow

  • Extend Base Layout: Override blocks (topbar, sidebar, breadcrumbs) in your child template.
  • Dynamic App Title: Set globally via config or per-request in Twig:
    {% set app_title = 'Posts Dashboard' %}
    
  • Bower Asset Updates: Re-run bower update after pulling SB Admin 2 updates.

2. CRUD Integration Pattern

  • Service Layer Abstraction:
    // src/Service/UserService.php
    class UserService extends EntityService {
        protected $entityClass = 'App\Entity\User';
        protected $defaultSort = ['name' => 'ASC'];
    
        public function getActiveUsers() {
            return $this->findBy(['active' => true]);
        }
    }
    
  • TableView Configuration:
    $tableView = $this->service->createTableView();
    $tableView->setItemsPerPage(20);
    $tableView->addColumn('email', 'Email')
              ->addColumn('active', 'Status', 'label'); // Uses Twig `label` filter
    $tableView->addRowAction('delete', 'Delete', ['route' => 'delete_user']);
    

3. Twig Extension Utilization

  • Bootstrap Labels:
    {{ is_active|label }}  {# Renders <span class="label label-success">Yes</span> #}
    
  • Pagination:
    {{ pagination(tableView) }}
    
  • Dynamic Buttons:
    {{ button('Save', 'btn-primary', { onclick: 'saveForm()' }) }}
    {{ buttonGroup([
        button('Edit', 'btn-info'),
        button('Delete', 'btn-danger')
    ]) }}
    

4. FOSUserBundle Integration

  • Override templates in resources/views/FOSUserBundle/ (e.g., registration.html.twig).
  • Extend the layout by including CtrlRad’s base template:
    {% extends 'CtrlRadBundle::layout.html.twig' %}
    {% block body %}
        {{ parent() }}
        {# FOSUser content #}
    {% endblock %}
    

Gotchas and Tips

1. Doctrine EntityService Quirks

  • Repository Method Conflicts: If findAll is overridden in your entity repo, specify a custom method in EntityService:
    protected $repositoryMethod = 'getPublishedPosts';
    
  • Lazy Loading: Ensure TableView columns reference loaded properties to avoid UndefinedPropertyException.

2. Twig Extension Pitfalls

  • Callable Filter: The call filter executes PHP callables. Use cautiously to avoid XSS:
    {{ user.getFullName()|call }}  {# Safe if `getFullName()` is trusted #}
    
  • Type Filter: is_type is case-sensitive:
    {% if value is iterable %}  {# Not `is_iterable` #}
    

3. Asset Management

  • Bower Dependency: If using Laravel Mix, alias Bower paths in webpack.mix.js:
    mix.sass('resources/sass/app.scss', 'public/css')
       .copy('vendor/bower_components/bootstrap/dist/css/bootstrap.css', 'public/css');
    
  • Cache Busting: Clear Twig cache after Bower updates:
    php artisan cache:clear
    

4. Debugging Tips

  • TableView Debugging: Dump the TableView object to inspect columns/actions:
    dump($tableView->getColumns());
    
  • Layout Overrides: Use {{ dump(app.request.attributes) }} to debug block inheritance.

5. Extension Points

  • Custom EntityService: Extend EntityService to add domain logic:
    class CustomEntityService extends EntityService {
        public function getWithRelations() {
            return $this->getEntityManager()
                ->getRepository($this->entityClass)
                ->findWithRelations();
        }
    }
    
  • Twig Globals: Add custom globals in config/packages/ctrl_rad.yaml:
    twig:
        globals:
            app_version: "1.0.0"
    

6. Laravel-Specific Workarounds

  • Service Container Binding: Manually bind Symfony services to Laravel’s container:
    $this->app->bind('ctrl_rad.entity_service', function ($app) {
        return new EntityService($app['doctrine.orm.entity_manager']);
    });
    
  • Routing Conflicts: Prefix Symfony routes to avoid clashes:
    # config/routes.yaml (Symfony)
    ctrl_rad_crud:
        resource: "@CtrlRadBundle/Resources/config/routing/crud.xml"
        prefix: /admin
    
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.
yandex/translate-api
voku/simple_html_dom
league/flysystem-vfs
bkwld/upchuck
filament/spatie-laravel-tags-plugin
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php