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

Nova Enum Field Laravel Package

simplesquid/nova-enum-field

Nova Enum Field adds a dedicated Laravel Nova field for PHP enums, letting you display and edit enum-backed model attributes as friendly selects or badges. Configure labels, colors, options, and validation for cleaner enum handling in Nova resources.

View on GitHub
Deep Wiki
Context7

Getting Started

Install with Composer; there is nothing to publish or configure:

composer require simplesquid/nova-enum-field

Requirements to confirm before you start, as of v3.3.0 (March 2025): PHP 8.2+, Laravel 11.x or 12.x, and Nova 4.x or 5.x. That release dropped PHP 8.1 and Laravel 10.x and added Nova 5 / Laravel 12 support — so if you are still on Laravel 10 or PHP 8.1, pin ^3.2 and stay there until you upgrade. Older Nova majors (3.x and below) need an older tag still; the 3.3 line targets the current Nova field API.

Define your enum as a backed enum so it can be persisted:

enum Status: string
{
    case Draft = 'draft';
    case Published = 'published';
}

Then swap your hand-maintained Select for the package field:

use SimpleSquid\Nova\Fields\Enum\Enum;

public function fields(Request $request): array
{
    return [
        Enum::make('Status')->attach(Status::class),
    ];
}

That single line gives you the form select, the index/detail display, and hydration from the model attribute. The first real use case is exactly this: replacing Select::make('status')->options([...]) that drifts out of sync with the enum every time someone adds a case.

Where to look first: the README for the canonical make/attach signatures (the v3.3 README is the only place the new Nova 5 constraint is spelled out), then src/Enum.php and the filter class — the package is small enough to read end-to-end in ten minutes, which is the fastest way to answer "does it support my label convention?".

Implementation Patterns

One field, three contexts. The same Enum::make(...) call works on forms, detail, and index. Keep it in a shared method (or a trait) if the resource is large, so the enum class is referenced in exactly one place.

Filters alongside the field. Register the enum filter in your resource's filters() method so index filtering uses the same source of truth:

use SimpleSquid\Nova\Fields\Enum\EnumFilter;

public function filters(Request $request): array
{
    return [
        EnumFilter::make('Status')->attach(Status::class),
    ];
}

Pair it with validation. The field renders options but does not add request rules. Add Rule::enum yourself:

'status' => ['required', Rule::enum(Status::class)],

If you cast the attribute ('status' => Status::class), the field still reads/writes the scalar backed value — the cast and the field don't conflict, they just operate at different layers.

Legacy enum libraries. If your codebase predates PHP 8.1 enums (BenSampo/laravel-enum or similar), the package is designed to accept those classes through the same attach() call, so you can standardise Nova resources on the package before migrating your enum implementation.

Actions and lenses. Because the field resolves options from the enum class, you can reuse the same attach() in action fields and lens fields without rewriting option arrays — the main payoff of the package over a plain select.

Customising the filter. For "any of these statuses" behaviour or a query that isn't a straight where, subclass the filter and override its query/options rather than writing a bespoke filter from scratch.

Upgrading to the 3.3 line. In practice the bump is a platform bump, not an API change: the make/attach surface is unchanged. Sequence it as Laravel → Nova → this package, run your resource tests against Nova 5's field rendering, and expect the only real work to be the PHP 8.2 minimum (readonly classes, null/false standalone types are available; deprecations from 8.1 dynamic properties start surfacing here).

Gotchas and Tips

  • attach() takes the class string, not an instance. Status::class, not new Status. Passing the wrong thing produces an empty select with no obvious error.
  • Store the backed value. The DB column should be a string/int matching the enum's backing type. A column that stores case names while the enum backs to lowercase values will look fine on the form and break on load.
  • Labels are the usual surprise. If options render as raw values (draft) instead of human labels, the package doesn't recognise your label convention. Add the expected description/label method to the enum, or override the option list on the field — check the README for which hook your version expects.
  • Nullable enums need both sides. Add ->nullable() on the field and make the column nullable; otherwise Nova will reject the empty option on submit while the select happily offers it.
  • Filter column, not accessor. The filter queries the database column directly. If you renamed the attribute in the model or use an accessor, pass the real column name.
  • Retired cases leave orphaned data. Removing an enum case doesn't rewrite old rows. The field won't render an unknown value, so index rows can look blank — add a migration or a fallback display if values are historical.
  • Version-pin aggressively, and mind the floor as well as the ceiling. v3.3.0 requires PHP 8.2+, Laravel 11/12, Nova 4/5. Pin explicitly — ^3.2 if you are on Laravel 10, ^3.3 once you've upgraded — because composer update on a Laravel 10 app will otherwise resolve down silently or fail on platform requirements in CI. This is still a small, low-star package (single maintainer, no dependents); a Nova major can change the field API, so be prepared to fork — the surface area is one field and one or two filter classes.
  • Keep the package's supported matrix in your CI. If you run a PHP/Laravel version matrix, add a job for the oldest combination the package claims (currently PHP 8.2 + Laravel 11 + Nova 4) so an upstream release that drops it shows up as a red build rather than a surprise in production.
  • Debugging checklist: Status::cases() for the source list, the attach() argument for the class, and dumps()/dd() on the field's resolved options if the select is empty.
  • Don't use it for pure (non-backed) enums. There's nothing to persist; keep those as plain Select options or convert them to backed enums first.
  • Extension point to remember: subclassing the field to override option resolution is trivial, which is often cheaper than waiting for an upstream change to label handling — and it's what keeps you off the upgrade treadmill when a Nova major lands.
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.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums