how to use table ->defaultGroup with enum field?
I want to use the new v3 table group feature with a column casted to PHP enum, but seem unable, what are some ways I can do it?
Code is something like $table->defaultGroup('status') where status is casted to enum
6 Replies
bump
Some code example in my ListOrders
As you can see, I do $record->status->value because my status is casted to a PHP Enum
having status as default group crashes, if i choose status as the group by choice, it crashes too
Error message is
Object of class App\Enums\OrderStatusEnum could not be converted to string
We need more information to help you debug your problem. Please click on the top left 'SHARE' button of the error page you're seeing and share the link with us.
I dig deeper, the error is thrown at strval()
i think because status is casted to php enum in my model, strval($order->status) throw that error.
It doesn't matter that I specified ->getTitleFromRecordUsing(fn (Order $record): string => $record->status->value),
The code does not reach that stage, it already fail at the Group::make('status') stage
So similarly i think the example in documentation will fail too. because if status does not pass strval() in Group::make('key') it crashes
i have also tried the following but same enum cannot convert to string error too. also at strval
i think fix will be if ($key instanceof Enum [is it backed enum or something else] ) {
$key = $key->value;
}
in the getKey() method
Hope it helps. Somebody can make a PR to filament table group to add this condition, im too shy to reveal my real name (& lazy to create an alternate github account). So i would just not use this feature on my site but if it affect u, u can make the fix i suggest above as a pr to filament, thanks!