main

filamentphp/demo

Last updated at: 29/12/2023 09:42

OrderStatus.php

TLDR

This file defines an enum class called OrderStatus in the App\Enums namespace. The class implements the HasColor and HasLabel contracts. It represents different order statuses and provides methods to retrieve the label and color associated with each status.

Methods

getLabel

This method returns the label associated with each order status.

getColor

This method returns the color associated with each order status.

<?php

namespace App\Enums;

use Filament\Support\Contracts\HasColor;
use Filament\Support\Contracts\HasLabel;

enum OrderStatus: string implements HasColor, HasLabel
{
    case New = 'new';

    case Processing = 'processing';

    case Shipped = 'shipped';

    case Delivered = 'delivered';

    case Cancelled = 'cancelled';

    public function getLabel(): string
    {
        return match ($this) {
            self::New => 'New',
            self::Processing => 'Processing',
            self::Shipped => 'Shipped',
            self::Delivered => 'Delivered',
            self::Cancelled => 'Cancelled',
        };
    }

    public function getColor(): string | array | null
    {
        return match ($this) {
            self::New => 'gray',
            self::Processing => 'warning',
            self::Shipped, self::Delivered => 'success',
            self::Cancelled => 'danger',
        };
    }
}