- How do I install osama-98/laravel-enum-translatable?
- Install it with Composer by running composer require osama-98/laravel-enum-translatable. Laravel's package auto-discovery should register the service provider if one is present, and the package does not require migrations or config publishing. You need PHP 8.1 or newer because it relies on backed enums.
- Which Laravel and PHP versions does laravel-enum-translatable support?
- It requires PHP 8.1+ for backed enums and works with any Laravel version still in support. The trait has no framework coupling, so it also drops into non-Laravel PHP services and shared domain packages. Check the repository's composer.json for the exact Laravel constraint before upgrading.
- How do I add translated labels and descriptions to enum cases?
- Apply the package's trait to a backed enum and define a translation key for each case, typically under a namespaced lang file. Then call the provided label() and description() methods in your views, API resources, or form options. The package resolves the keys through Laravel's translator using the current locale.
- Does laravel-enum-translatable support multiple languages and locale switching?
- Yes. It uses Laravel's translation system, so labels and descriptions follow the application locale set by App::setLocale() or the request middleware. You provide one lang file per locale, and the package resolves the correct string at call time. No per-locale enum classes are needed.
- Do I need to publish config or run migrations for laravel-enum-translatable?
- No. The package is adopted per enum via a trait and per call site via its helper methods, with no migrations, config publishing, or service provider changes implied. That keeps integration small and reversible. Confirm in the README if your version adds optional config.
- How do I test enum translations in Laravel?
- Set the application locale in your test, then assert that the enum's label() or description() returns the same value as the corresponding trans() key. Use PHPUnit or Pest data providers to cover each case and locale. Because the package delegates to Laravel's translator, you do not need to mock it.
- Is laravel-enum-translatable production-ready and friendly to static analysis?
- The package is dependency-light and does not touch the database, container, or HTTP layer, so it is low-risk in production. Version 2.4 narrows the wrap() return type to ?static, which improves PHPStan and Psalm results at call sites. Expect a few new static-analysis errors if downstream code assigned results to wider BackedEnum types.
- What breaking changes are in version 2.4 of laravel-enum-translatable?
- Version 2.4 changes the EnumWrappable trait's wrap() behavior: foreign enum pass-through is removed, strict mode now throws ValueError, and '0'-backed cases are fixed. Audit any call site that passes non-homogeneous or externally sourced enum values, especially at HTTP and queue boundaries. Pin the version if you relied on the old pass-through, because this is a runtime change shipped under a minor release.
- What are alternatives to laravel-enum-translatable?
- Alternatives include benSampo/laravel-enum and archtechx/enums for broader enum helpers, or writing label() and description() methods directly on your backed enums with Laravel's __() helper. If you only need display strings, a small custom trait with translation keys is often enough. Choose based on whether you need translations, value wrapping, or both.
- Is laravel-enum-translatable maintained and suitable for large Laravel applications?
- It is a narrow, high-leverage utility that is cheap to adopt and cheap to remove, which suits large codebases that already use backed enums as domain vocabulary. The 2.4 release shows the maintainer is willing to make behavioral changes in minor versions, so review upgrade notes and pin versions in production. It does not impose an architectural pattern or constrain application design.