MedicOneSystems / livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS
https://livewire-datatables.com/
MIT License
1.19k stars 258 forks source link

Pass relationship column to callback #418

Open alexandergziresis opened 2 years ago

alexandergziresis commented 2 years ago

Hello!, when i try pass a relationship variable in a callback i get an error (example roles.name), but in a simple column works fine

NikarashiHatsu commented 2 years ago

Refer to the Relation example.

So, in the columns method, you can write Column::callback(['roles.name'], closure()), and at the bottom of the file (or anywhere) add the getRolesProperty() method.

Example code:

public function columns()
{
    return [
        Column::callback(['roles.name']), function($role_name) {
             return $role_name;
        }),
    ];
}

public function getRolesProperty()
{
    Roles::all();
}

Tell me if you have any issues.