PHP code example of laravel-enso / enums

1. Go to this page and download the library: Download laravel-enso/enums library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laravel-enso / enums example snippets


return [
    'vendors' => ['laravel-enso'],
];

use LaravelEnso\Enums\Services\Enum;

class Roles extends Enum
{
    public const Admin = 1;
    public const Supervisor = 2;
    public const User = 3;
}

Roles::get(1);
Roles::has(2);
Roles::keys();
Roles::values();
Roles::select();
Roles::json();

use LaravelEnso\Enums\Contracts\Frontend;
use LaravelEnso\Enums\Contracts\Mappable;
use LaravelEnso\Enums\Traits\Select;

enum Status: int implements Frontend, Mappable
{
    use Select;

    case Draft = 0;
    case Published = 1;

    public static function registerBy(): string
    {
        return 'statuses';
    }

    public function map(): mixed
    {
        return match ($this) {
            self::Draft => 'Draft',
            self::Published => 'Published',
        };
    }
}

use LaravelEnso\Enums\Facades\Enums;

Enums::register([
    'roles' => \App\Enums\Roles::class,
]);
bash
php artisan vendor:publish --tag=enums-config
bash
php artisan vendor:publish --tag=enum-provider