PHPackages                             intrfce/laravel-frontend-enums - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. intrfce/laravel-frontend-enums

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

intrfce/laravel-frontend-enums
==============================

Stop using 'magic' strings/numbers in your frontend Javascript and use your actual application enums instead.

v1.0.1(2mo ago)2320.6k↓43.7%1MITPHPPHP ^8.4.0CI passing

Since Oct 24Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/intrfce/laravel-frontend-enums)[ Packagist](https://packagist.org/packages/intrfce/laravel-frontend-enums)[ Docs](https://github.com/intrfce/laravel-frontend-enums)[ RSS](/packages/intrfce-laravel-frontend-enums/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (19)Used By (0)

Laravel Frontend Enums
======================

[](#laravel-frontend-enums)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f9e6a199d0b965f8a77eec089e674f50e9cd1503ba142ae4d3a5259f92525958/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e74726663652f6c61726176656c2d66726f6e74656e642d656e756d732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/intrfce/laravel-frontend-enums)[![Total Downloads](https://camo.githubusercontent.com/ccf5742fc11b240a253640ef58f5d324c9100ab2958cb5ec406ba75c19ed4caa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e74726663652f6c61726176656c2d66726f6e74656e642d656e756d732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/intrfce/laravel-frontend-enums)[![GitHub Actions](https://github.com/intrfce/laravel-frontend-enums/actions/workflows/main.yml/badge.svg)](https://github.com/intrfce/laravel-frontend-enums/actions/workflows/main.yml/badge.svg)

Publish your PHP enums to the front-end of your application, so you can refer to them in your JavaScript code.

This means less reliance on "magic strings".

```
// Before:

if (myValue === 'name') {
  // Do something
}

// After
import {UserProfileField} from './UserProfileField.enum.js';

if (myValue === UserProfileField.Name) {
  // Do something.
}
```

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require intrfce/laravel-frontend-enums
```

Usage
-----

[](#usage)

### Just add the attribute!

[](#just-add-the-attribute)

Add the `#[PublishEnum]` attribute to any enum you want published to the frontend - it's that easy.

```
use Intrfce\LaravelFrontendEnums\Attributes\PublishEnum;

#[PublishEnum]
enum MyEnum: string {
    case Foo = 'foo';
    case Bar = 'bar';
}
```

Then run the publish command:

```
php artisan publish:enums-to-javascript
```

Your enums will be waiting at `resources/js/Enums` with the extension `.enum.js`:

```
import {MyEnum} from './Enums/MyEnum.enum.js';

console.log(MyEnum.Foo); // 'foo'
```

### Configuration

[](#configuration)

Publish the config file to customise the output path and discovery directories:

```
php artisan vendor:publish --tag=config --provider="Intrfce\LaravelFrontendEnums\LaravelFrontendEnumsServiceProvider"
```

```
// config/laravel-frontend-enums.php
return [

    // Customise the output directory.
    'publish_to' => resource_path('js/Enums'),

    // Customise the folders scanned for enum classes
    'discover_in' => [
        app_path(),
    ],

    // Always output as typescript enums.
    'as_typescript' => true,

];
```

The `discover_in` array supports glob patterns, which is useful for modular or monorepo layouts:

```
'discover_in' => [
    app_path(),
    base_path('app-modules/*/src'),
],
```

Typescript Support
------------------

[](#typescript-support)

Enable TypeScript output globally via the config file:

```
'as_typescript' => true,
```

Or override per-enum using the attribute:

```
#[PublishEnum(asTypescript: true)]  // Force TypeScript for this enum
#[PublishEnum(asTypescript: false)] // Force JavaScript for this enum
#[PublishEnum]                      // Follow the global config setting
```

TypeScript enums are output as `.ts` files:

```
export enum MyEnum {
    Foo = "foo",
    Bar = "bar",
}
```

Automatically generate javascript files on change.
--------------------------------------------------

[](#automatically-generate-javascript-files-on-change)

You can use the [`vite-plugin-watch`](https://github.com/lepikhinb/vite-plugin-watch) package from [lepikhinb](https://github.com/lepikhinb) to automatically generate your javascript files when you make changes to your PHP enums:

```
npm install -D vite-plugin-watch
```

Then add the plugin to your `vite.config.js`:

```
import { defineConfig } from "vite"
import { watch } from "vite-plugin-watch"

export default defineConfig({
  plugins: [
    watch({
      pattern: "app/Enums/**/*.php",
      command: "php artisan publish:enums-to-javascript",
    }),
  ],
})
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Dan Matthews](https://github.com/intrfce)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance86

Actively maintained with recent releases

Popularity37

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 97.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~61 days

Recently: every ~44 days

Total

15

Last Release

75d ago

Major Versions

v0.7.8 → v1.0.02026-03-04

PHP version history (3 changes)v0.5PHP ^8.1.0

v0.7.1PHP ^8.2.0

v0.7.7PHP ^8.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e103145d2ee7625eacb8d240214a90e4c54b8add29ea4433be0b02416e553974?d=identicon)[danmatthews](/maintainers/danmatthews)

---

Top Contributors

[![danmatthews](https://avatars.githubusercontent.com/u/149426?v=4)](https://github.com/danmatthews "danmatthews (69 commits)")[![coclav](https://avatars.githubusercontent.com/u/1837434?v=4)](https://github.com/coclav "coclav (2 commits)")

---

Tags

intrfcelaravel-frontend-enums

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/intrfce-laravel-frontend-enums/health.svg)

```
[![Health](https://phpackages.com/badges/intrfce-laravel-frontend-enums/health.svg)](https://phpackages.com/packages/intrfce-laravel-frontend-enums)
```

###  Alternatives

[wireui/wireui

TallStack components

1.8k1.3M16](/packages/wireui-wireui)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[ramonrietdijk/livewire-tables

Dynamic tables for models with Laravel Livewire

21147.4k](/packages/ramonrietdijk-livewire-tables)[mrmarchone/laravel-auto-crud

Laravel Auto CRUD helps you streamline development and save time.

28711.8k2](/packages/mrmarchone-laravel-auto-crud)[aerni/livewire-forms

A Statamic forms framework powered by Laravel Livewire

2912.8k](/packages/aerni-livewire-forms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
