Closed eafarooqi closed 7 months ago
Hi @eafarooqi,
Following your example, add the column with a different name than gender
, for instance gender label
.
public function addColumns(): PowerGridColumns
{
return PowerGrid::columns()
->addColumn('id')
->addColumn('name')
->addColumn('gender_label', function (User $person) {
return $person->gender->label();
});
Then, when including the column, use the gender_label
source:
public function columns(): array
{
return [
Column::make('Id', 'id'),
Column::make('gender', 'gender_label'),
//....
];
}
You should be getting the label of your Enum in the table:
Hello @dansysanalyst
thank you so much for the solution. That i have already figured it out that the enum columns can be used with this work around. But is it a bug? or is it a limitation in this package that the enum columns cant be used in the default way ?
Have you searched through other issues to see if your problem is already reported or has been fixed?
Yes, I did not find it.
Did you read the documentation?
Yes, I did not find it.
Have you tried to publish the views?
Yes - I didn't work.
Is there an error in the console?
No
PHP Version
8.1.0
PowerGrid
5.3.1
Laravel
10.42.0
Livewire
3.4.1
Alpine JS
3.12.0
Theme
Bootstrap
Describe the bug.
I have an enum field which is include in the $cast attribute as enum. As per document i am getting the following error. "Male" is not a valid backing value for enum "App\Enums\Person\Gender"
cast property in model
Gender enum
Column
This only works when cast is removed from the model and column is changed to as follows (as in documentation). But i cannot remove the cast.
getting the following error in this case. preg_replace(): Argument # 3 ($subject) must be of type array|string, App\Enums\Person\Gender given
or as follows
The error is same as the first one. "Male" is not a valid backing value for enum "App\Enums\Person\Gender"
To Reproduce...
Add enum column to the cast propery in model.