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 Db Enum Generator Laravel Package

dobron/laravel-db-enum-generator

Laravel package that generates PHP enum classes from database column values, keeping enum cases in sync with stored data. Useful for replacing magic strings with type-safe enums in models, validation rules, and forms.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. buy vs. vendor (recommendation: vendor/steal, don't depend). The capability is small enough to reproduce in-house in under a day, so the real decision is whether to invest 1–2 engineer-days writing our own generator or adopt and fork this one. Either way the artifact is the same: a repeatable command that keeps PHP enum classes in lockstep with the database instead of hand-maintained constant lists.
  • Roadmap: PHP 8.1+ enum adoption. If the roadmap includes tightening type safety or modernizing a legacy codebase, this is a cheap acceleration lever for the least glamorous part of that work — backfilling enums for status/type/category columns that already exist in production.
  • Defect-class elimination. Every hand-written const STATUS_ACTIVE = 'active' is a silent-drift risk against the DB. This shifts a recurring, low-severity bug class (typo'd status strings, values present in DB but missing in code, casing mismatches) into a generated, diffable artifact — a measurable reduction in support tickets and incident noise for admin/reporting features.
  • Feature scoping for legacy-adjacent work. When scoping features on a mature schema (reporting filters, admin status pickers, bulk state transitions), the estimate depends heavily on whether enum values are discoverable or must be reverse-engineered. A generator command turns that discovery step into a one-liner, making those stories easier to size and less likely to blow up mid-sprint.
  • Onboarding and documentation. Generated enum classes double as living documentation of the domain vocabulary (order states, account tiers, event types), which shortens ramp-up for new engineers and makes code review conversations concrete.
  • Migration sequencing. Informs whether we attack database normalization (lookup tables) first or accept the existing ENUM/VARCHAR columns and generate code from them — a genuine sequencing decision that affects how much schema churn we commit to this quarter.
  • Not a fit for: runtime validation, UI label/i18n mapping, or serialization contracts. Those are separate concerns (validation rules, translation files, API resources) and should not be conflated with code generation when allocating scope.

When to Consider This Package

Adopt (or fork) when:

  • The schema is mature or inherited: many ENUM columns and/or small reference tables whose values are authoritative in the database, not in migrations we control.
  • The stack is PHP 8.1+ and the team has already accepted backed enums as the convention for domain vocabularies.
  • There is a recurring, manual "did we update the constants?" step in PRs or release checklists that we want to delete.
  • The values change on a database-driven cadence (ops or data team edits them), so hand-editing PHP would otherwise be a standing chore.
  • We need a fast, low-cost evaluation: MIT license, single artisan command, removable in an afternoon if it disappoints.

Look elsewhere or build in-house when:

  • Greenfield with controlled migrations. If migrations are the source of truth, define enums by hand alongside them; a DB-reading generator inverts the dependency and creates a bootstrapping problem in CI (no database at build time).
  • Maintenance risk is unacceptable. 3 stars, 0 dependents, and a last release in September 2023 indicate a single-maintainer side project with no adoption signal. Treat it as reference code to vendor into app/Console/Commands with a test, not as a Composer dependency on a critical path — and definitely not something to pin a platform strategy to.
  • You need more than class generation. If the requirement is validation (Rule::enum), API serialization, labels/localization, or TypeScript type parity for a frontend, compose purpose-built tools instead; this only emits PHP.
  • CI needs deterministic, database-free builds. Regenerating from a live DB in CI is a flaky-test generator. Prefer generation as a deliberate, committed-diff developer action with a drift check.
  • Postgres native enums or a lookup-table normalization effort is already planned. Either would invalidate the generated output shortly after adoption.

How to Pitch It (Stakeholders)

To executives (one paragraph): This is a small, free, MIT-licensed utility that generates PHP enum classes directly from our database schema. It is not a platform bet — it is a low-cost accelerator for a specific, unglamorous chore: keeping status and type values in code synchronized with the database. The expected return is fewer small defects from typo'd or stale string constants and faster onboarding onto legacy parts of the schema. Because the project has minimal community traction and no recent release, I recommend we spend roughly one engineer-day to vendor the command into our own codebase rather than take a runtime dependency, so we capture the benefit with zero long-term maintenance exposure. Decision requested: approve the one-day spike; success is measured by whether it removes the manual "update the constants" step from our release checklist.

To engineering: The command reads enum columns and reference tables and emits backed enums, deleting a class of drift bugs and giving us IDE autocomplete and static analysis on domain values. Run it as an explicit, committed step — never in CI against a live database — and add a test asserting generated output matches the schema so drift surfaces as a failing build rather than a production bug. Two caveats to plan around: the upstream package is effectively unmaintained (last release September 2023), so fork it into app/Console/Commands with our own tests; and it only covers PHP, so validation rules, labels, and any frontend type generation remain separate workstreams. Do not let generated enums become the de facto contract for API payloads without an explicit serialization decision.

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.
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
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