How do I fix Enum could not be converted into string when using export action?

enum CitizenStatus: string implements HasColor, HasLabel
{
case UNCHECKED = "Unchecked";

case CHECKED = "Checked";

case REJECTED = "Rejected";

case ACCEPTED = 'Accepted';

case FINALIZED = "Finalized";

case VOTED = "Voted";

public function getColor(): string|array|null
{
return match ($this) {
self::ACCEPTED => Color::hex('#00ff00'),
self::REJECTED => Color::hex('#ff0000'),
self::UNCHECKED => Color::hex('#808080'),
self::CHECKED => Color::hex('#00cdff'),
self::FINALIZED => Color::hex('#999100'),
self::VOTED => Color::hex('#0000ff')
};
}


public function getLabel(): ?string
{
return $this->name;
}
}
enum CitizenStatus: string implements HasColor, HasLabel
{
case UNCHECKED = "Unchecked";

case CHECKED = "Checked";

case REJECTED = "Rejected";

case ACCEPTED = 'Accepted';

case FINALIZED = "Finalized";

case VOTED = "Voted";

public function getColor(): string|array|null
{
return match ($this) {
self::ACCEPTED => Color::hex('#00ff00'),
self::REJECTED => Color::hex('#ff0000'),
self::UNCHECKED => Color::hex('#808080'),
self::CHECKED => Color::hex('#00cdff'),
self::FINALIZED => Color::hex('#999100'),
self::VOTED => Color::hex('#0000ff')
};
}


public function getLabel(): ?string
{
return $this->name;
}
}
public static function getColumns(): array
{
return [
ExportColumn::make('status')
]
}
public static function getColumns(): array
{
return [
ExportColumn::make('status')
]
}
I want to know how to format the state of the enum without the "could not be converted to string" error. Its the $state itself that is in type string throwing the error. Without the $state in the ->state(function ($state) { function it works well.
protected $casts = [
'status' => CitizenStatus::class,
];
protected $casts = [
'status' => CitizenStatus::class,
];
^ I don't think this is relevant but here is the cast
0 Replies
No replies yetBe the first to reply to this messageJoin