Closed bradleybernard closed 1 year ago
See the last commit of my repro for the more important pieces, the first 2 commits were just Laravel install, then Filament install:
https://github.com/bradleybernard/FilamentEnumBug/commit/250c062763ebb7364c0f0d24206129d461c62961
Would appreciate a PR to fix this if you can
Will do sometime this week, if not next week :) thanks Dan!
Opened up https://github.com/filamentphp/filament/pull/7962 but would love some eyes on it @danharrin! :)
I am having a similar problem using a string type enumerator.
<?php
namespace App\Enums;
use Filament\Support\Contracts\HasLabel;
enum WaitlistStatus: string implements HasLabel
{
case WAITING = 'waiting';
case CALLED = 'called';
public function getLabel(): ?string
{
return match ($this) {
self::WAITING => 'Na fila',
self::CALLED => 'Chamado',
};
}
}
@php
$canSelectPlaceholder = $canSelectPlaceholder();
$isDisabled = $isDisabled();
$state = $getState();
dd($state);
@endphp
App\Enums\WaitlistStatus {#3167 ▼ // vendor/filament/tables/src/../resources/views/columns/select-column.blade.php
+name: "WAITING"
+value: "waiting"
}
Returns the error: Object of class App\Enums\WaitlistStatus could not be converted to string
Making this change works... but obviously, the solution must be more complex.
Package
filament/filament
Package Version
v3.0.7
Laravel Version
10.17.1
Livewire Version
v3.0.0-beta.7
PHP Version
8.2.8
Problem description
Issue
When using an enum that is backed by int and used in a table, there is code in
select-column.blade.php
that tries to stringify the enum value, but int enums do not support__toString()
unfortunately, so we might need to check explicitly for this case and manually convert the enum's value to string.See code below, exception fires when visiting:
admin/users
Exception
Object of class App\Enums\UserProviderType could not be converted to string
Code
UserProviderType.php
:UserResource.php
:`User.php:
select-column.blade.php
:Expected behavior
Since int backed enums can easily be translated to string, we can use reflection or other mechanism to detect and provide the string value?
select-column.blade.php
Oddly enough, it works on the edit page, just not on the select column in the table. The enum is hooked up roughly the same way, but it's the
Select
component, not theSelectColumn
:So maybe bringing some code over from
Select
intoSelectColumn
:)Steps to reproduce
Reproduction repository
https://github.com/bradleybernard/FilamentEnumBug
Relevant log output
No response