raid/core-enum is a Laravel package for raid core enum.
It currently has 0 GitHub stars and 49 downloads on Packagist.
Install it with composer require raid/core-enum.
Discover more Laravel packages by raid
or browse all Laravel packages to compare alternatives.
Last updated
This package is responsible for handling all enums in the system.
The package using the archtechx/enums package as a base for the enums.
composer require raid/core-enum
php artisan core:publish-enum
class PostController extends Controller
{
/**
* Invoke the controller method.
*/
public function __invoke(Request $request): JsonResponse
{
$adminType = UserTypeEnum::ADMIN;
$guestType = UserTypeEnum::GUEST;
$userType = UserTypeEnum::USER;
$userTypeConstants = UserTypeEnum::constants();
$hasAdminConstant = UserTypeEnum::hasConstant('ADMIN');
}
}
Let's create our const enum class and prefer classes as they ar extendable.
You can use this command to create your enum class.
php artisan core:make-enum UserTypeEnum
<?php
namespace App\Models\Enums;
use Raid\Core\Enum\Models\Enum;
class UserTypeEnum extends Enum
{
}
Let's add our constants.
<?php
namespace App\Models\Enums;
use Raid\Core\Enum\Models\Enum;
class UserTypeEnum extends Enum
{
public const ADMIN = 'admin';
public const GUEST = 'guest';
public const USER = 'user';
}
You can create a case enum class, use this command to create the case enum class.
php artisan core:make-case-enum UserTypeEnum
<?php
namespace App\Models\Enums;
use Raid\Core\Enum\Traits\Enum\CaseEnum;
enum UserTypeEnum
{
use CaseEnum;
}
Let's add our constants.
<?php
namespace App\Models\Enums;
use Raid\Core\Enum\Traits\Enum\CaseEnum;
enum UserTypeEnum: string
{
use CaseEnum;
case ADMIN = 'admin';
case USER = 'user';
case GUEST = 'guest';
}
You can work with this class as archtechx/enums class.
You can create a cont enum class, use this command to create the case enum class.
php artisan core:make-cont-enum UserTypeEnum
<?php
namespace App\Models\Enums;
use Raid\Core\Enum\Traits\Enum\ContEnum;
enum UserTypeEnum
{
use ContEnum;
}
Let's add our constants.
<?php
namespace App\Models\Enums;
use Raid\Core\Enum\Traits\Enum\ContEnum;
enum UserTypeEnum: string
{
use ContEnum;
case ADMIN = 'admin';
case USER = 'user';
case GUEST = 'guest';
}
You can use these methods to work with const enums.
UserTypeEnum::constants() to get all constants as an array.UserTypeEnum::hasConstant('ADMIN') to check if the constant exists.And that's it.
The MIT License (MIT). Please see License File for more information.
If you discover any security-related issues, please email instead of using the issue tracker.
Raid is a PHP framework created by Mohamed Khedr, and it is maintained by Mohamed Khedr.
Raid is an MIT-licensed open-source project. It's an independent project with its ongoing development made possible.