---
title: "Badge colours and presentation — Enums for Laravel | Roundly"
description: "Give each case a colour with HasColor; presentation() and presentations() return {value, label, color} DTOs for badges and status chips."
url: https://roundly-consulting.com/open-source/docs/enums-for-laravel/presentation
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Enums for Laravel](https://roundly-consulting.com/open-source/docs/enums-for-laravel.md)

# Badge colours and presentation

Available from 1.1.0. For badges and status chips, an enum can give each case a colour by implementing RoundlyConsulting\\Enums\\Contracts\\HasColor. presentation() then returns one case as an EnumPresentation DTO, and presentations() every case in declaration order:

```php
use RoundlyConsulting\Enums\Attributes\TranslatedLabels;
use RoundlyConsulting\Enums\Contracts\HasColor;
use RoundlyConsulting\Enums\Helpers;

#[TranslatedLabels]
enum OrderStatus: string implements HasColor
{
    use Helpers;

    case Pending = 'pending';
    case Shipped = 'shipped';

    public function color(): string
    {
        return match ($this) {
            self::Pending => 'warning',
            self::Shipped => 'success',
        };
    }
}

OrderStatus::Shipped->presentation();     // EnumPresentation {value: 'shipped', label: 'Na ceste', color: 'success'}
OrderStatus::presentations();             // Collection<int, EnumPresentation>, every case in declaration order
OrderStatus::presentations()->toJson();   // [{"value":"pending","label":"…","color":"warning"}, …]
```

- The colour is a free-form string your front end understands — a badge variant, a CSS class, a hex code. The package passes it through and never interprets it.
- HasColor is an interface, not a trait method, so an enum that already has a color() method with another return type keeps working: it gets color: null in its presentations until it implements the interface.
- presentation() uses the backed value (the case name on a pure enum) with its native type, so an int stays an int, and readable() for the label, so translated labels and readable() overrides apply. presentations() maps presentation() over every case.
- Without HasColor, color is null.
- options() keeps its {value, label, name} shape for selects; use presentations() when you need the colour.

## The EnumPresentation DTO

| Member | Type | Value |
| --- | --- | --- |
| `value` | `string\|int` | The backed value with its native type — the case name on a pure enum. |
| `label` | `string` | readable() — translated. |
| `color` | `?string` | color() under HasColor, otherwise null. |
| `toArray()` | `array` | `['value' => ..., 'label' => ..., 'color' => ...]` |
| `jsonSerialize()` | `array` | Same as toArray(). |

RoundlyConsulting\\Enums\\DataTransferObjects\\EnumPresentation is a final readonly class implementing Arrayable and JsonSerializable: toArray() and json\_encode() always give exactly value, label and color, in that order, so presentations() goes straight into a JSON response or an Inertia prop.

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/enums-for-laravel.md)
