PHP code example of hxm / enum

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

    

hxm / enum example snippets



namespace App\Enums;

use HXM\Enum\Abstracts\EnumBase;

class ExampleEnums extends EnumBase
{
    const E1 = 1;
    const E2 = 2;

    protected static $descriptions = [
        1 => 'description for E1'
    ];
}

  ExampleEnums::E1; // 1
  
  ExampleEnums::getValueWithDescriptions()->toArray(); // [1 => 'description for E1', 2 => "E2"]
  
  ExampleEnums::getValues()->toArray(); // [1, 2]
  
  ExampleEnums::getDescription(1); // 'description for E1'
  

class ExampleClass extends Model
{
  protected $casts = [
          ....
          'attribute' => ExampleEnums::class,
          ...
      ];
}


Validator:make($data, [
  'attribute' => ['