PHP code example of lfyw / lfyw-enum

1. Go to this page and download the library: Download lfyw/lfyw-enum 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/ */

    

lfyw / lfyw-enum example snippets




namespace App\Enums;

use Lfyw\LfywEnum\Enumable;
use Lfyw\LfywEnum\HasEnum;

enum UserType:string implements Enumable
{
    use HasEnum;

    //以下为添加的示例内容
    case ADMIN = 'admin';
    case CONSUMER = 'consumer';
}



namespace App\Enums;

use Lfyw\LfywEnum\Enumable;
use Lfyw\LfywEnum\HasEnum;

enum UserType:string implements Enumable
{
    use HasEnum;

    //以下为添加的示例内容
    case ADMIN = 'admin';
    case CONSUMER = 'consumer';

    public static function getDescriptions():array
    {
        return [
            UserType::Admin->name => 'super admin',
            UserType::Consumer->name => 'super consumer'
        ];
    }
}

public function rules()
{
    return [
        'value' => [new EnumValue(Status::class, false)],
        'name' => [new EnumName(Status::class)],
    ];
}

shell
$ php artisan make:enum UserType