two different enum class in one resource

It seems like I may have identified a bug, but I'm not certain. I have a resource (RepairResource) where both in the table and in the infolist, I display a repairState and a paymentState, which are two different ENUMs. When I need to use the ENUMs of paymentState, I encounter this error: "Pending" is not a valid backing value for the App\Enums\RepairStatus enum. This is because the enums are being searched in the wrong place. Here's the code:

...
use App\Enums\RepairStatus;
use App\Enums\PaymentStatus;
...

# infolist
...
Components\TextEntry::make('repair_status')
->label('Repair status')
->badge(),
Components\TextEntry::make('payment_status')
->label('Payment status')
->badge(),
...

...
use App\Enums\RepairStatus;
use App\Enums\PaymentStatus;
...

# infolist
...
Components\TextEntry::make('repair_status')
->label('Repair status')
->badge(),
Components\TextEntry::make('payment_status')
->label('Payment status')
->badge(),
...
If there's an issue where the Pending value is being treated as a value for RepairStatus enum instead of PaymentStatus
Solution:
Sounds like you specified the wrong cast
Jump to solution
10 Replies
Soundmit
SoundmitOP13mo ago
do i need to replicate the paymentStatus ENUM inside the repairStatus ENUM? but if i put the paymentStatus inside the repiarStatus, when i need to use the repairStatus (for example in a select) i see also the paymentStatus..
Dennis Koch
Dennis Koch13mo ago
This is because the enums are being searched in the wrong place.
What does that mean?
Soundmit
SoundmitOP13mo ago
both this ... Components\TextEntry::make('repair_status') ->label('Repair status') ->badge(), Components\TextEntry::make('payment_status') ->label('Payment status') ->badge(), ... search the ENUMS in enums/repairStatus.php but the enum definition for payment_status are in enums/paymentStatus.php
Soundmit
SoundmitOP13mo ago
when i want to update a repairStatus i see also the paymentStatus
No description
Solution
Dennis Koch
Dennis Koch13mo ago
Sounds like you specified the wrong cast
Dennis Koch
Dennis Koch13mo ago
As there is no filament logic in your code that would map stuff to enums
Soundmit
SoundmitOP13mo ago
And does the code default to that of RepairStatus? How can I specify which one to use?
Dennis Koch
Dennis Koch13mo ago
Can you show your model casts?
Soundmit
SoundmitOP13mo ago
doh... i've just realized protected $casts = [ 'repair_status' => RepairStatus::class, 'payment_status' => RepairStatus::class, 'accessories' => 'array', ]; need to change here thanks
Dennis Koch
Dennis Koch13mo ago
Yeah, that's what I said.
Want results from more Discord servers?
Add your server