So I have been upgrading an existing table for users on an app. As soon as i try to add multiple callbacks that use['id'] i get the Duplicate error.
The two callback Columns involved are these:
Column::callback(['id'], function($id) {
return User::find($id)->roles->first()->name;
})
->label('Role'),
Column::callback(['id'], function($id) {
return view('tables.user.flags', ['id' => $id]);
})->label('Flags'),
Removing either of these makes the table work. I realise that as both are using the id field and this is the most likely reason for the error but my question is how can i resolve this? I have tried adding in a name() and an Attribute in User for role but nothing worked and I mainly got errors about columns not being found in the users table in the database.
Not sure if it helps but the Role column is using Spatie/laravel-permission
. The flags column however does use columns that are in the User model (is_card_holder, is_account_handler) but shows other flags too.
I am new to Medicones solution having tried to use datatables.net (I had mulitple issues with this so it is being phased out) and rappasoft laravel livewire tables (worked well but lost a lot of search and sort functionality from many columns) I have been told that the one to go with which has the flexibility needed is the mediconesystems solution and so here I am....
Use different keys for each callback:
Column::callback(['role_id' => 'id'], function($id) {
return User::find($id)->roles->first()->name;
})
->label('Role'),
Column::callback(['flag_id' => 'id'], function($id) {
return view('tables.user.flags', ['id' => $id]);
})->label('Flags'),