Weave Code
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport