MedicOneSystems / livewire-datatables

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

Column::callback(): Argument #1 ($columns) must be of type string, array given #429

Open code23-barna opened 2 years ago

code23-barna commented 2 years ago

In src/Column.php:118 you set the type to "string" when it should be Array|String

Raised a PR to fix it: https://github.com/MedicOneSystems/livewire-datatables/pull/428

Lirux commented 2 years ago

The problem with this merge is, that's it's not working with PHP 7 anymore.

thyseus commented 2 years ago

Sure that PHP7 is not able to do type hint?

Lirux commented 2 years ago

I think not. Am I correct? https://www.php.net/manual/de/language.types.declarations.php#language.types.declarations.composite.union

code23-barna commented 2 years ago

Could be a solution to drop the type declarations?

gabepettus commented 2 years ago

I had this same issue, I was using a string to make the names unique. I changed the string to a dummy array value. Seems like a better solution would be to use the label with generating the internal callback name.

            Column::callback(['aqua_camp_weeks.id'], function($id) {
                return ('<a href="'. route('add-camper-to-session', ["id" => $id]) .'" 
                class="p-1 text-blue-600 hover:bg-blue-600 hover:text-white rounded">
                Add Child </a>');
            }**,['a']**) //array ['a'] at end is required since the callback is id all the callback functions have the same name
            ->label('Add Child')
            ->unsortable()
            ->excludeFromExport(),
            Column::callback(['aqua_camp_weeks.id'], function($id) {
                    return $this->weekStatus[$id];
                },**['b']**)
                ->unsortable()
                ->label('Week Status'),