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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata