New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

well35/laravel-enum-objects

Generate frontend enum objects from PHP enums, so backend enums are the single source of truth.
1,179 6

Larablocks Analysis

well35/laravel-enum-objects works with Laravel 11, 12 and 13 (latest release v1.1.0, Aug 4, 2026).

Promising: maintained and up to date, meets 2 of 4 checks; not yet widely used.

  • Works with Laravel 13, the current version
  • Released in the last 12 months (Aug 4, 2026)
  • 850 downloads a month (needs 10,000)
  • 6 GitHub stars (needs 100)

State

Actively maintained
  • Last stable release: Aug 4, 2026.
  • 5 releases in the last 12 months.
  • First released: Jul 15, 2026.
  • Monthly downloads: 850.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 5, 2026.

Install
composer require well35/laravel-enum-objects
Latest Version:v1.1.0
PHP:^8.4
Laravel:11 · 12 · 13
License:MIT
Last Updated:Aug 4, 2026
Links: GitHub  ·  Packagist
Maintainer: Well35

laravel-enum-objects

Tests Latest Version on Packagist Total Downloads License

Generate frontend enum objects from your PHP enums, so the backend enum is the single source of truth.

Unlike spatie/laravel-typescript-transformer, which generates types, this package generates data. Your frontend gets objects it can iterate for option lists, labels, and metadata, and the union types come from that data.

enum BrowseSort: string
{
    case Newest = 'newest';
    case Popular = 'popular';

    public function label(): string
    {
        return match ($this) {
            self::Newest => 'Newest',
            self::Popular => 'Most played',
        };
    }
}

becomes resources/js/enums/BrowseSort.ts:

export const BrowseSort = {
    Newest: { name: "Newest", value: "newest", label: "Newest" },
    Popular: { name: "Popular", value: "popular", label: "Most played" },
} as const;

export type BrowseSort = (typeof BrowseSort)[keyof typeof BrowseSort]["value"];

so the frontend can do:

import { BrowseSort } from '@/enums/BrowseSort';

Object.values(BrowseSort)          // option lists with labels
BrowseSort.Popular.value           // no magic strings
const foo: BrowseSort = 'newest'   // union type 'newest' | 'popular'
const bar: BrowseSort = 'newst'    // Error: tyop caught before runtime

Installation

composer require well35/laravel-enum-objects

Usage

php artisan enum-objects:generate

Every enum under App\Enums (nested namespaces mirror into subdirectories) gets one file in resources/js/enums. Commit the generated files and .enum-objects.json.

When an enum is renamed or deleted, its old file is pruned on the next run. Pruning is manifest based and non-destructive. Only files the package itself wrote (listed in the manifest) are ever deleted.

Labels

If the enum has a label() method it is called per case, otherwise the label falls back to Str::headline() of the case name (VeryHigh → "Very High").

Extra properties

The rule: static values go on the case, computed values go on a method.

use Well35\EnumObjects\Attributes\ComputedProperty;
use Well35\EnumObjects\Attributes\ObjectProperty;

enum ItemRarity: string
{
    #[ObjectProperty('icon', 'circle')]
    case Common = 'common';

    #[ObjectProperty('icon', 'sparkle')]
    case Legendary = 'legendary';

    #[ComputedProperty]                 // exported as `color`
    public function color(): string
    {
        return match ($this) {
            self::Common => '#999',
            self::Legendary => '#f90',
        };
    }

    #[ComputedProperty('sortWeight')]   // key override
    public function weight(): int { /* ... */ }
}

ComputedProperty methods must be callable without arguments. Keys are emitted exactly as you write them (ComputedProperty defaults to the method name).

ObjectProperty on the enum class itself adds the property to every case:

#[ObjectProperty('group', 'items')]     // all cases get group: "items"
enum ItemRarity: string { ... }

On a key collision the most specific declaration wins: case-level ObjectProperty beats ComputedProperty beats class-level ObjectProperty beats the built-ins.

Keys can also be backed-enum cases instead of strings, so you can define your own key enum instead of repeating strings:

enum PropKeys: string { case Group = 'group'; }

#[ObjectProperty(PropKeys::Group, 'items')]

Excluding cases or enums

#[Excluded] keeps a case out of the generated object, or if placed on the enum class, skips the enum entirely:

use Well35\EnumObjects\Attributes\Excluded;

enum Priority: int
{
    case Low = 1;

    #[Excluded]
    case Internal = 99;   // never sent to the frontend
}

Excluded cases drop out of the union type too, so don't exclude anything the API still returns.

Inertia, Vue, React

The generated files are plain data, so nothing framework specific to set up.

Laravel serializes backed enums to their value, so an enum sent through an Inertia prop (or any JSON response) arrives already matching the generated type:

return Inertia::render('Browse', [
    'sort' => BrowseSort::Popular,   // arrives as 'popular'
]);
defineProps<{ sort: BrowseSort }>();   // 'newest' | 'popular'

Vue: a select built from the enum:

<script setup lang="ts">
import { BrowseSort } from '@/enums/BrowseSort';
</script>

<template>
    <select>
        <option v-for="option in BrowseSort" :key="option.name" :value="option.value">
            {{ option.label }}
        </option>
    </select>
</template>

React: extra properties looked up from the value the backend sent:

import { ItemRarity } from '@/enums/ItemRarity';

export function RarityBadge({ rarity }: { rarity: ItemRarity }) {
    const meta = Object.values(ItemRarity).find(option => option.value === rarity)!;

    return <span style={{ color: meta.color }}>{meta.label}</span>;
}

Keeping frontend and backend in sync

Add this one test and CI fails whenever an enum changed without regeneration:

use Well35\EnumObjects\EnumObjects;

test('enum objects are in sync', fn () => EnumObjects::assertInSync());

Or in CI:

php artisan enum-objects:generate --check

Dev watcher

The package ships a Vite plugin that reruns the generator whenever a PHP enum changes, so the browser reloads with the new objects:

// vite.config.js
import enumObjects from './vendor/well35/laravel-enum-objects/vite-plugin.mjs';

export default defineConfig({
    plugins: [laravel({ /* ... */ }), enumObjects()],
});

Configuration

php artisan vendor:publish --tag=enum-objects-config
return [
    'paths' => ['App\\Enums' => 'app/Enums'], // namespace => directory
    'output_path' => 'resources/js/enums',    // generated files + manifest go here
    'format' => 'ts',                         // ts | json
    'label_method' => 'label',
    // output keys for the built-in properties
    'name_key' => 'name',
    'value_key' => 'value',
    'label_key' => 'label',
];

Formatters

Keep your formatter off the generated files, or it will fight the sync check:

# .prettierignore
resources/js/enums

Caveats

  • Pure (unbacked) enums generate with the case name as value and trigger a warning: PHP can't json_encode a pure enum, so if it's ever sent to or received from the frontend, back it.
  • Deleting .enum-objects.json orphans the generated files. The package forgets it wrote them, so renamed/removed enums stop being pruned. Regenerating recreates the manifest.

Credits

The backend-enums-as-single-source-of-truth generator this package grew from was IronSinew's idea and original implementation.

License

MIT

Alternatives to well35/laravel-enum-objects

splitstack/laravel-enum-friendly

Make your Laravel enums friendly with TypeScript, selects, and many more conveni...

22,050 1
wthealth/laravel-enum-transformer

Transforms bensampo/laravel-enum enums to TypeScript with spatie/typescript-tran...

88,091 2
olivermbs/enumshare

A Laravel package to export PHP Enums to TypeScript with labels, metadata, and t...

4,865 1
gigerit/laravel-morphmap-js-generator

Generate frontend JavaScript/TypeScript constants from Laravel morph map configu...

1,023 0
devwizardhq/laravel-enumify

Auto-generate TypeScript enums and types from Laravel PHP enums with an Artisan...

2,611 8

Version History

Version Released PHP Laravel License
v1.1.0 ^8.4 ^11.0|^12.0|^13.0 MIT
v1.0.0 ^8.4 ^11.0|^12.0 MIT
v0.2.0 ^8.4 ^11.0|^12.0 MIT
v0.1.1 ^8.4 ^11.0|^12.0 MIT
v0.1.0 ^8.4 ^11.0|^12.0 MIT