Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Where exactly should I place the Widget::add() call in my CrudController
    Laravel Backpack CRUD operations custom CSS custom JavaScript Widget::add() setupListOperation setup method config/backpack/base.php


Where exactly should I place the Widget::add() call in my CrudController


there are a few places where you can place the `Widget::add()` call in your CrudController to add custom CSS or JavaScript:

1. Inside the `setupListOperation()` method:
If you want the custom CSS or JavaScript to be loaded only on the List operation, you can place the `Widget::add()` call inside the `setupListOperation()` method.

php
   public function setupListOperation()
   {
       // Other list operation setup
       Widget::add()->type('css')->asset('css/custom-crud.css');
       Widget::add()->type('js')->asset('js/custom-crud.js');
   }
   

2. Inside the `setup()` method:
If you want the custom CSS or JavaScript to be loaded on all CRUD operations, you can place the `Widget::add()` call inside the `setup()` method.

php
   public function setup()
   {
       // Other CRUD setup
       Widget::add()->type('css')->asset('css/custom-crud.css');
       Widget::add()->type('js')->asset('js/custom-crud.js');
   }
   

3. In the `config/backpack/base.php` file:
Alternatively, you can add the custom CSS and JavaScript files in the `config/backpack/base.php` file under the `scripts` and `styles` sections.

php
   // config/backpack/base.php
   'scripts' => [
       'packages/backpack/base/js/admin.js',
       'js/custom-crud.js',
   ],
   'styles' => [
       'packages/backpack/base/css/admin.css',
       'css/custom-crud.css',
   ],
   

This will include the custom CSS and JavaScript files on all CRUD pages.

The search results indicate that the `bp-section` attribute is used to target specific CRUD operations or sections, so you can use this in your custom CSS or JavaScript to apply styles or behaviors to specific parts of the CRUD interface.

Citations:
[1] https://backpackforlaravel.com/docs/6.x/crud-how-to
[2] https://laracasts.com/discuss/channels/eloquent/add-cruds-controller-method-to-a-controller
[3] https://backpackforlaravel.com/docs/6.x/getting-started-crud-operations
[4] https://www.digitalocean.com/community/tutorials/simple-laravel-crud-with-resource-controllers
[5] https://kinsta.com/blog/laravel-crud/