Skip to content

Enum Integration

PHP enums that implement HasTableDisplay get first-class badge rendering with automatic text labels and colours.

Implementing the Interface

php
use Forjed\InertiaTable\Contracts\HasTableDisplay;

enum ServerStatus: string implements HasTableDisplay
{
    case Active = 'active';
    case Failed = 'failed';
    case Pending = 'pending';

    public function getText(): string
    {
        return match ($this) {
            self::Active => 'Active',
            self::Failed => 'Failed',
            self::Pending => 'Pending',
        };
    }

    public function getColor(): string
    {
        return match ($this) {
            self::Active => 'success',
            self::Failed => 'danger',
            self::Pending => 'warning',
        };
    }
}

Using in a Table

php
use Forjed\InertiaTable\Columns\EnumColumn;

// Using the typed column
EnumColumn::make('status', 'Status')->sortable()

// Or using the base Column with modifier
Column::make('status', 'Status')->sortable()->enum()

How It Works

  • getText() is used as the display value in the badge
  • getColor() determines the badge variant (success, danger, warning, info, default, outline)
  • If the value is not a HasTableDisplay instance, it falls back to the raw value

Available Colours

The frontend maps colour names to Tailwind classes:

ColourLight ModeDark Mode
successGreen badgeGreen badge (dark)
dangerRed badgeRed badge (dark)
warningYellow badgeYellow badge (dark)
infoBlue badgeBlue badge (dark)
defaultGray badgeGray badge (dark)
grayGray badge (alias)Gray badge (dark)
destructiveRed badgeRed badge (dark)
outlineTransparent with borderBorder (dark)