Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
2.99k stars 880 forks source link

afterColumn() doesn't work from custom trait. #5498

Open karandatwani92 opened 2 months ago

karandatwani92 commented 2 months ago

Discussed in https://github.com/Laravel-Backpack/community-forum/discussions/904

Originally posted by **cdo9** March 29, 2024 Hello, this is my "setupHasStatusDefaults" function code from my "HasStatusOperation" trait : ``` $this->crud->operation('list', function () { $this->crud->addColumn([ 'name' => 'status', 'label' => 'status', 'type' => 'enum', ])->afterColumn('id'); }); ``` The column is added, but before any column (first one). Maybe because the HasStatusOperation is loaded before the setupListOperation ? Is there a way to do it after ? I would love to make operations like that to add columns/filters/fields to CRUDs that need it. **EDIT : for now I added ->makeFirst(); to my ID column, so this does the trick to put the field in 2nd**

Hey @pxpm

Please take a look at the details in the above discussion.

I tested it and the user is right. I also thought the list closure runs in the setup() before setupListOperation, so I removed setupListOperation() and moved columns in the list closure inside setup() of CRUD. Still the same result.

Apart from this, I also found: