livewire-datatables icon indicating copy to clipboard operation
livewire-datatables copied to clipboard

Pass relationship column to callback

Open alexandergziresis opened this issue 3 years ago • 1 comments

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

alexandergziresis avatar Mar 19 '22 11:03 alexandergziresis

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.

NikarashiHatsu avatar Mar 25 '22 09:03 NikarashiHatsu