PHP code example of splitstack / laravel-enum-friendly

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

    

splitstack / laravel-enum-friendly example snippets


use Splitstack\EnumFriendly\Traits\ExtendedEnum;

enum Status: string
{
  use ExtendedEnum;

  case ACTIVE = 'active';
  case INACTIVE = 'inactive';
}

use Splitstack\EnumFriendly\Traits\ExtendedEnum;

enum MyEnum: string
{
  use ExtendedEnum;

  case ADMIN = 'admin';
  case USER = 'user';
}

Status::toTypeScript();
// Returns:
// [
//   'type' => 'Status',
//   'values' => ['active', 'inactive']
// ]

Status::toSelectOptions();
// Returns:
// [
//   ['value' => 'active', 'label' => 'Active'],
//   ['value' => 'inactive', 'label' => 'Inactive']
// ]

Status::rules(['equired', 'string', 'in:active,inactive']
bash
php artisan split:enum Status --type=string active:ACTIVE inactive:INACTIVE