Skip to main content
Back to packages
2,028 GitHub stars

BenSampo/laravel-enum

View on GitHub

Description

Simple, extensible and powerful enumeration implementation for Laravel

You can use the following Artisan command to generate a new enum class:

php artisan make:enum UserType

Now, you just need to add the possible values your enum can have as constants.

<?php declare(strict_types=1);
 
namespace App\Enums;
 
use BenSampo\Enum\Enum;
 
final class UserType extends Enum
{
const Administrator = 0;
const Moderator = 1;
const Subscriber = 2;
const SuperAdministrator = 3;
}

That's it! Note that because the enum values are defined as plain constants, you can simply access them like any other class constant.

UserType::Administrator // Has a value of 0

Recent Courses on Laravel Daily

Next.js Basics for Laravel Developers

11 lessons
58 min

Laravel 13 Eloquent: Expert Level

41 lessons
1 h 34 min

Queues in Laravel 13

18 lessons
1 h 12 min read