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
[NEW] Practical Laravel Security: Packages, Secrets, Supply-Chain Attacks
7 lessons
43 min read
Queues in Laravel 13
18 lessons
1 h 12 min read
How to Build Laravel 13 API From Scratch
30 lessons
1 h 23 min