levintoo/laravel-enum-exporter
Composer 安装命令:
composer require levintoo/laravel-enum-exporter
包简介
Laravel dev-only package to export PHP enums to TypeScript
README 文档
README
Effortlessly sync PHP enums to TypeScript for type-safe frontend integration.
This dev-only Laravel package exports your PHP enums into TypeScript files under resources/js/enums, letting you use the same enum definitions on the frontend as your server.
📦 Installation
composer require levintoo/laravel-enum-exporter --dev
🚀 Usage
Export a single enum (TypeScript):
php artisan export:enum Role
# or
php artisan export:enum app/Enums/Role.php
Export all enums in app/Enums (TypeScript):
php artisan export:enum --all
Export enums as JavaScript workarounds (instead of TypeScript):
php artisan export:enum Role --js
# or
php artisan export:enum --all --js
🗂 Output Path TypeScript files are generated in:
- TypeScript:
resources/js/enums/{kebab-case-enum}.ts - JavaScript:
resources/js/enums/{kebab-case-enum}.js
📝 Example
Given a PHP enum:
/* app/Enums/UserStatus.php */ enum UserStatus: string { case Active = 'active'; case Inactive = 'inactive'; case Pending = 'pending'; }
The following TypeScript file will be generated:
/* resources/js/enums/user-status.ts */ export enum UserStatus { Active = 'active', Inactive = 'inactive', Pending = 'pending', }
or The following Javascript file will be generated:
/* resources/js/enums/user-status.js */ const UserStatus = { Active: { name: 'Active', value: 'active' }, Inactive: { name: 'Inactive', value: 'inactive' }, Pending: { name: 'Pending', value: 'pending' }, cases() { return Object.values(this).filter(e => e?.value !== undefined); }, from(slug) { return this.cases().find( e => e.name.toLowerCase() === slug ) ?? null; }, get(value) { return this.cases().find( e => e.value === value ) ?? null; } }; export default UserStatus;
⚠️ Current Status
This package is pre-alpha: APIs and behavior are actively evolving and may change without notice.
🛠 Future Plans
| Feature | Status |
|---|---|
| Publish to Packagist | ⏳ Planned |
| Support enums with methods/properties | ⏳ Planned |
| Add option to overwrite existing files | ⏳ Planned |
| Allow custom output paths for TS files | ⏳ Planned |
| Support multiple case styles (kebab, Pascal) | ⏳ Planned |
| Support JS enum workarounds | ⏳ Planned |
levintoo/laravel-enum-exporter 适用场景与选型建议
levintoo/laravel-enum-exporter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 levintoo/laravel-enum-exporter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 levintoo/laravel-enum-exporter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-05