| name | type-bridge-enum-generation |
| description | Generates TypeScript/JavaScript enums from PHP backed enums using the type-bridge:enums Artisan command. Use when user says "generate TS enums", "sync enums to frontend", "type-bridge enums", or needs PHP enum values available in JavaScript/TypeScript. |
Laravel Type Bridge - Enum Generation
When to use this skill
Use this skill when you need to:
- Generate frontend enum files from PHP enums
- Set up enum synchronization between backend and frontend
- Use the opt-in attribute for specific enums
- Run CI drift detection
Overview
This package (gaiatools/laravel-type-bridge) generates TypeScript/JavaScript enums from PHP backed enums. Check the actual configuration in config/type-bridge.php for paths and output settings.
Available Commands
php artisan type-bridge:enums
php artisan type-bridge:enums --format=js
php artisan type-bridge:enums --format=ts
php artisan type-bridge:enums --check
php artisan type-bridge:enums --dirty
Opt-in Enum Generation
Use the #[GenerateEnum] attribute to explicitly mark enums for generation:
<?php
namespace App\Enums;
use GaiaTools\TypeBridge\Attributes\GenerateEnum;
#[GenerateEnum]
enum ThemeVisibility: string
{
case Private = 'private';
case Unlisted = 'unlisted';
case Public = 'public';
}
GenerateEnum Attribute Options
use GaiaTools\TypeBridge\Attributes\GenerateEnum;
#[GenerateEnum]
enum Status: string
{
case Active = 'active';
case Inactive = 'inactive';
}
#[GenerateEnum(requiresComments: true)]
enum Status: string { ... }
#[GenerateEnum(outputFormat: 'js')]
enum Status: string { ... }
#[GenerateEnum(includeMethods: ['staffRoles', 'memberRoles'])]
enum UserRole: string { ... }
Enum Groups
Enum groups export curated subsets alongside the base enum. Define public static methods that return arrays:
<?php
namespace App\Enums;
use GaiaTools\TypeBridge\Attributes\GenerateEnum;
#[GenerateEnum(includeMethods: ['staffRoles', 'memberRoles'])]
enum UserRole: string
{
case Admin = 'admin';
case Manager = 'manager';
case Support = 'support';
case Member = 'member';
case Guest = 'guest';
public static function staffRoles(): array
{
return [self::Admin, self::Manager, self::Support];
}
public static function memberRoles(): array
{
return [self::Member->value, self::Guest->value];
}
}
Generated TypeScript output:
export const UserRole = {
Admin: 'admin',
Manager: 'manager',
Support: 'support',
Member: 'member',
Guest: 'guest',
} as const;
export type UserRole = typeof UserRole[keyof typeof UserRole];
export const StaffRoles = {
Admin: UserRole.Admin,
Manager: UserRole.Manager,
Support: UserRole.Support,
} as const;
export const MemberRoles = [
UserRole.Member,
UserRole.Guest,
] as const;
CI Integration
Use --check mode in CI to detect drift between PHP enums and generated frontend files:
php artisan type-bridge:enums --check