Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Enum

Laravel Enum Laravel Package

mad-web/laravel-enum

A Laravel package that provides a lightweight enum implementation with model attribute casting, validation rules, translations, and helper methods for working with predefined values throughout your application.

View on GitHub
Deep Wiki
Context7

Elegant Enum implementation for Laravel. With make:enum command, ability to casting for Eloquent models and labels translations via lang files.

Frequently asked questions about Laravel Enum
How do I install mad-web/laravel-enum in a Laravel app?
Install it with composer require mad-web/laravel-enum; the service provider is auto-discovered. Optionally publish the package lang files if you want to override label translations per locale. Then run php artisan make:enum Status to scaffold an enum class and add it to a model's $casts array. No schema migration is needed if the underlying column is already a string or integer.
Is mad-web/laravel-enum actively maintained and safe to use in production?
Public project-health signals are weak: the repository shows zero stars, zero dependents and no visible release cadence, which suggests it is effectively unvetted. There is no evidence of CI coverage against current Laravel LTS or PHP 8.2/8.3. Treat it as a small, reversible convenience layer rather than a core dependency, and pin the version if you adopt it. For new projects, verify the code yourself or prefer native PHP enums.
Does this package support Laravel 10, Laravel 11, PHP 8.2 and PHP 8.3?
There is no documented evidence that it is tested against Laravel 10/11 or PHP 8.2/8.3. Before any spike, check the composer.json version constraints against your pinned Laravel and PHP versions. Because it only adds a service provider, a make:enum command and casts, it may still run, but an untested claim is a real upgrade risk. If the constraint is wide-open or targets older Laravel, expect to fork or avoid it.
How does Eloquent attribute casting work with mad-web/laravel-enum?
You register an enum class in a model's $casts array, and Eloquent hydrates the attribute as an enum instance instead of a raw scalar; the database still stores a string or integer. This gives you typed comparisons and helper methods in your domain code. Be aware that casting throws when a stored value is not one of the enum cases, which is dangerous against legacy rows with dirty data. Audit each column and use a tryFrom-with-logging fallback at read boundaries until the data is clean.
What happens if a database row contains a value that is not in the enum?
Native-style enum casting will throw a ValueError when the stored value does not match any case. That can break listing pages, API endpoints and background jobs on legacy data. Mitigate by auditing existing values first and wrapping reads with tryFrom that returns null and logs the anomaly. Never enable casting on a column until you have confirmed its values are a strict subset of the enum cases.
Can I use mad-web/laravel-enum alongside bensampo/laravel-enum or native Laravel enum casting?
Running two enum libraries in one codebase is an anti-pattern and will create conflicting idioms. If you are already standardized on bensampo/laravel-enum, do not add this package. On Laravel 9+ with PHP 8.1+, native backed enums plus first-class Eloquent enum casting cover most of this package's value, leaving only the label-translation convention. Choose one approach per project and document it.
How are translated enum labels resolved through lang files?
The package resolves human-readable labels through Laravel's translation system, so you can publish or define lang files per locale and return a translated string for each enum case. Confirm that labels are loaded from lang files rather than runtime config so config:cache and route:cache do not break them. This label convention is the most durable reason to use the package. If you only need labels, a small HasLabels trait on native enums may be a cheaper option.
Should I adopt this package on PHP 8.1+ or Laravel 9+?
Probably not as a new dependency. PHP 8.1 shipped native enums and Laravel 9 added first-class enum casting, so roughly 70% of the package's value now lives in the framework. The remaining benefit is the make:enum scaffold and the lang-file label convention. If you adopt it, do so behind an internal seam so you can replace it with native enums later.
How should I test enum casts and JSON output before shipping?
Start with a data audit query that confirms every stored value maps to a declared case. Add feature tests for one model that read a known row, assert the cast returns an enum instance, and assert invalid data is handled by your fallback rather than throwing. Add API contract tests comparing toArray() and JSON output before and after enabling the cast, because enum instances can silently change payload shape. Keep the pilot on a single model until these tests are green.
How do I remove mad-web/laravel-enum later, and how hard is the migration?
Removal is architecturally cheap because the package does not change persistence: the database still stores scalars. Adopt it behind an internal interface or trait, migrate one bounded domain and column at a time, and audit data before each step. When you are ready to exit, swap the package casts for native PHP enum casts or plain constants, move labels into a HasLabels trait, and drop the dependency. Budget a few hours per model rather than a big-bang refactor.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager