Skip to main content
Badge enums are PHP backed enums that implement BadgeSerializable via the SerializeAsBadge trait. Once an enum is badge-serializable, Core can render it as a styled badge chip anywhere in the UI — in table columns, page headers, DTOs, and forms — without any per-callsite configuration.

Defining a Badge Enum

app/Enums/CompanyStatus.php
namespace App\Enums;

use Inly\Core\Enums\Contracts\BadgeSerializable;
use Inly\Core\Enums\CoreVariant;
use Inly\Core\Enums\Traits\SerializeAsBadge;

enum CompanyStatus: string implements BadgeSerializable
{
    use SerializeAsBadge;

    case ACTIVE = 'active';
    case INACTIVE = 'inactive';
    case PENDING = 'pending';

    public function label(): string
    {
        return match ($this) {
            self::ACTIVE => __('Active'),
            self::INACTIVE => __('Inactive'),
            self::PENDING => __('Pending'),
        };
    }

    public function variant(): CoreVariant
    {
        return match ($this) {
            self::ACTIVE => CoreVariant::SUCCESS,
            self::INACTIVE => CoreVariant::SECONDARY,
            self::PENDING => CoreVariant::WARNING,
        };
    }
}

Variants

VariantColorUse case
DEFAULTGrayNeutral states
SECONDARYMutedInactive, disabled
SUCCESSGreenActive, completed
DESTRUCTIVERedErrors, deletions
WARNINGYellowPending, caution
INFOBlueInformational
BRANDPurpleFeatured, branded

Using in a DTO

Use the #[WithCastable] attribute to serialize the enum as BadgeData in your DTO:
use Inly\Core\Data\BadgeData;
use Spatie\LaravelData\Attributes\WithCastable;

#[WithCastable(CompanyStatus::class)]
public BadgeData $status
This makes status available as a BadgeData object on the frontend, which the <CoreBadge> component renders directly.

Using in a Table Column

use Inly\Core\Tables\Columns\CoreBadgeColumn;

CoreBadgeColumn::make('status', __('Status'), sortable: true)

Using in a Page Badge

Pass the enum directly to ->badge() on a page — no manual BadgeData construction needed:
return CoreShowPage::make('companies/company-show')
    ->fromDomainObject($company)
    ->badge($company->status);

Rendering in React

import CoreBadge from '@/core/components/core-badge';

<CoreBadge data={company.status} />
The data prop accepts the BadgeData object produced by the DTO.