Use ENUMS in controller
I have a controller that print a pdf
now i need to use an ENUM, but i always get errors
My code is
the error
Non-static method App\Enums\WarrantyDurationSpan::getLabel() cannot be called statically
4 Replies
maybe show the full code
not useful outside the context
but
enum
value in $record->repairWarranty->duration_span == Days
i've found this solution but please, tell me if there is a better way
$dspan = match ($record->repairWarranty->duration_span->value) {
'Days' => WarrantyDurationSpan::DAYS->getLabel(),
'Months' => WarrantyDurationSpan::MONTHS->getLabel(),
'Years' => WarrantyDurationSpan::YEARS->getLabel(),
};
You got enums wrong. You can call the method on the enum instance.
->duration_span->getLabel()
but i've tried in 2 different way and get always error