PHP code example of dilovanmatini / laravel-enumable

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

    

dilovanmatini / laravel-enumable example snippets


use DilovanMatini\Enumable\Traits\Enumable;

enum YourEnum: string
{
    use Enumable;

    case Example = 'example';
    // Add your cases here
}

// Class methods
YourEnum::values(); // ['example']
YourEnum::names(); // ['Example']
YourEnum::labels(); // ['example' => 'Example']
YourEnum::getCase('example'); // YourEnum::Example
YourEnum::getName('example'); // 'Example'
YourEnum::getLabel('example'); // 'Example'
YourEnum::toArray(); // ['example' => 'Example']
YourEnum::toCollection(); // Collection {#1 ▼
    #items: App\Enums\YourEnum [▼
        "name" => "Example",
        "value" => "example",
    ]
}
YourEnum::toSelectArray(); // ['example' => 'Example']
YourEnum::exists('example'); // true
YourEnum::random(); // YourEnum::Example
YourEnum::default(); // YourEnum::Example
YourEnum::first(); // YourEnum::Example
YourEnum::last(); // YourEnum::Example
YourEnum::count(); // 1
YourEnum::only(['Example']); // YourEnum::Example
YourEnum::except(['Example']); // YourEnum::Example
YourEnum::generate(['Example']); // YourEnum::Example

// Instance methods
YourEnum::Example->label(); // 'Example'
YourEnum::Example->headline(); // 'Example'
YourEnum::Example->str()->camel(); // 'example'
YourEnum::Example->str()->plural(); // 'Examples'

public static function setLabels(): array
{
    return [
        self::Example->value => 'Example Custom Label',
    ];
}