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

Enum Laravel Package

konekt/enum

Lightweight PHP enum base class (pre-PHP 8.1) for defining value-safe constants via abstract Enum subclasses. Simple instantiation, validation and utilities, with docs and optional Laravel Eloquent integration via konekt/enum-eloquent.

View on GitHub
Deep Wiki
Context7

Nullable Enums

In certain circumstances it's useful to have enums that can have a null value. Usually this null value is also the default, however this is not mandatory.

This can be done by explicitly defining a constant that has a null value:

Example:

class Gender extends \Konekt\Enum\Enum
{
    const __DEFAULT = self::UNKNOWN;
    
    const UNKNOWN = null;
    const MALE    = 'm';
    const FEMALE  = 'f';
}

$gender = new Gender();
var_dump($gender->value());
// NULL

$unknown = Gender::UNKNOWN();
var_dump($unknown->value());
// NULL

Next: Comparing Enums »

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.
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin