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
WarrantyDurationSpan::class)->getLabel($record->repairWarranty->duration_span)
WarrantyDurationSpan::class)->getLabel($record->repairWarranty->duration_span)
the error Non-static method App\Enums\WarrantyDurationSpan::getLabel() cannot be called statically
4 Replies
krekas
krekas7mo ago
maybe show the full code
Soundmit
SoundmitOP7mo ago
not useful outside the context but
use App\Enums\WarrantyDurationSpan;

class DownloadRegularController extends Controller
{
public function download(Repair $record)
{
....
$enumValue = WarrantyDurationSpan::getLabel($record->repairWarranty->duration_span)

...
use App\Enums\WarrantyDurationSpan;

class DownloadRegularController extends Controller
{
public function download(Repair $record)
{
....
$enumValue = WarrantyDurationSpan::getLabel($record->repairWarranty->duration_span)

...
enum
...
enum WarrantyDurationSpan: string implements HasLabel, HasColor, HasIcon
{
case DAYS = 'Days';
case MONTHS = 'Months';
case YEARS = 'Years';


.....
...
enum WarrantyDurationSpan: string implements HasLabel, HasColor, HasIcon
{
case DAYS = 'Days';
case MONTHS = 'Months';
case YEARS = 'Years';


.....
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(), };
Dennis Koch
Dennis Koch7mo ago
You got enums wrong. You can call the method on the enum instance. ->duration_span->getLabel()
Soundmit
SoundmitOP7mo ago
but i've tried in 2 different way and get always error
Want results from more Discord servers?
Add your server