PHP code example of nasyrov / laravel-enums

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

    

nasyrov / laravel-enums example snippets

 php
'providers' => [
    ...
    Nasyrov\Laravel\Enums\EnumServiceProvider::class,
    ...
]
 bash
$ php artisan make:enum UserStatusEnum
 php
$status = new UserStatusEnum(UserStatusEnum::ACTIVE);
$status = UserStatusEnum::ACTIVE();
 php
public function getStatusAttribute($attribute) {
    return new UserStatusEnum($attribute);
}
 php
public function setStatusAttribute(UserStatusEnum $attribute) {
    $this->attributes['status'] = $attribute->getValue();
}
 php
$this->validate($request, [
    'status' => [
        '
 php
use Nasyrov\Laravel\Enums\Enum as BaseEnum;

abstract class Enum extends BaseEnum
{
    /**
     * Get the enum labels.
     *
     * @return array
     */
    public static function labels()
    {
        return static::constants()
            ->flip()
            ->map(function ($key) {
                // Place your translation strings in `resources/lang/en/enum.php`
                return trans(sprintf('enum.%s', strtolower($key)));
            })
            ->all();
    }
}