Laravel Enum with Filament

How can I render enum in laravel blade? When I add laravel casting like this
protected $casts = [
'type' => EmploymentType::class,
];
protected $casts = [
'type' => EmploymentType::class,
];
I can't render in blade file.
<span
class="my-auto ml-3 rounded bg-pink-100 px-2.5 py-0.5 text-sm font-medium text-pink-800 dark:bg-pink-900 dark:text-pink-300">
{{ __(EmploymentType::tryFrom($post->type)->name) }}
</span>
<span
class="my-auto ml-3 rounded bg-pink-100 px-2.5 py-0.5 text-sm font-medium text-pink-800 dark:bg-pink-900 dark:text-pink-300">
{{ __(EmploymentType::tryFrom($post->type)->name) }}
</span>
App\Enums\EmploymentType::tryFrom(): Argument #1 ($value) must be of type string|int, App\Enums\EmploymentType given
App\Enums\EmploymentType::tryFrom(): Argument #1 ($value) must be of type string|int, App\Enums\EmploymentType given
Solution:
You already casted the value to an enum. No need for a tryFrom() again. Just use it
Jump to solution
5 Replies
Solution
Dennis Koch
Dennis Koch13mo ago
You already casted the value to an enum. No need for a tryFrom() again. Just use it
Shaung Bhone
Shaung BhoneOP13mo ago
Thank you
Soundmit
Soundmit9mo ago
have you solved this?
Dennis Koch
Dennis Koch9mo ago
Best to open a new thread with your issue and code.
Soundmit
Soundmit9mo ago
done on #mokhosh-kanban channel
Want results from more Discord servers?
Add your server