{"id":20309184,"url":"https://github.com/nasyrov/laravel-enums","last_synced_at":"2025-08-12T13:06:23.322Z","repository":{"id":55457555,"uuid":"94034692","full_name":"nasyrov/laravel-enums","owner":"nasyrov","description":"Laravel package for Enum implementation.","archived":false,"fork":false,"pushed_at":"2020-12-29T15:01:17.000Z","size":36,"stargazers_count":33,"open_issues_count":0,"forks_count":9,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-06T15:45:14.920Z","etag":null,"topics":["enum","laravel","laravel-package","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nasyrov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-11T22:07:26.000Z","updated_at":"2023-12-25T13:47:31.000Z","dependencies_parsed_at":"2022-08-15T00:40:41.016Z","dependency_job_id":null,"html_url":"https://github.com/nasyrov/laravel-enums","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/nasyrov/laravel-enums","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nasyrov%2Flaravel-enums","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nasyrov%2Flaravel-enums/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nasyrov%2Flaravel-enums/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nasyrov%2Flaravel-enums/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nasyrov","download_url":"https://codeload.github.com/nasyrov/laravel-enums/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nasyrov%2Flaravel-enums/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270065427,"owners_count":24520946,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["enum","laravel","laravel-package","php"],"created_at":"2024-11-14T17:26:06.064Z","updated_at":"2025-08-12T13:06:23.292Z","avatar_url":"https://github.com/nasyrov.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Enums\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE.md)\n[![Build Status][ico-travis]][link-travis]\n[![Coverage Status][ico-scrutinizer]][link-scrutinizer]\n[![Quality Score][ico-code-quality]][link-code-quality]\n[![Total Downloads][ico-downloads]][link-downloads]\n\nLaravel package for Enum implementation.\n\n## Requirements\n\nMake sure all dependencies have been installed before moving on:\n\n* [PHP](http://php.net/manual/en/install.php) \u003e= 7.0\n* [Composer](https://getcomposer.org/download/)\n\n## Install\n\nPull the package via Composer:\n\n``` bash\n$ composer require nasyrov/laravel-enums\n```\n\nRegister the service provider in `config/app.php`:\n\n``` php\n'providers' =\u003e [\n    ...\n    Nasyrov\\Laravel\\Enums\\EnumServiceProvider::class,\n    ...\n]\n```\n\n## Usage\n\nGenerate a new enum class via the command:\n\n``` bash\n$ php artisan make:enum UserStatusEnum\n```\n\nDefine the enum constants:\n\n``` php\n/**\n * @method static UserStatusEnum ACTIVE()\n * @method static UserStatusEnum INACTIVE()\n */\nclass UserStatusEnum extends Enum\n{\n    const ACTIVE = 10;\n    const INACTIVE = 20;\n}\n```\n\nTo use the enum new up the instance or simply call via the static methods:\n\n``` php\n$status = new UserStatusEnum(UserStatusEnum::ACTIVE);\n$status = UserStatusEnum::ACTIVE();\n```\n\nType-hint the model accessor:\n\n``` php\npublic function getStatusAttribute($attribute) {\n    return new UserStatusEnum($attribute);\n}\n```\n\nType-hint the model mutator:\n\n``` php\npublic function setStatusAttribute(UserStatusEnum $attribute) {\n    $this-\u003eattributes['status'] = $attribute-\u003egetValue();\n}\n```\n\nValidation:\n\n``` php\n$this-\u003evalidate($request, [\n    'status' =\u003e [\n        'required',\n        Rule::in(UserStatusEnum::values()),\n    ],\n]);\n```\n\nLocalization:\n\n``` php\nuse Nasyrov\\Laravel\\Enums\\Enum as BaseEnum;\n\nabstract class Enum extends BaseEnum\n{\n    /**\n     * Get the enum labels.\n     *\n     * @return array\n     */\n    public static function labels()\n    {\n        return static::constants()\n            -\u003eflip()\n            -\u003emap(function ($key) {\n                // Place your translation strings in `resources/lang/en/enum.php`\n                return trans(sprintf('enum.%s', strtolower($key)));\n            })\n            -\u003eall();\n    }\n}\n```\n\n``` blade\n\u003cselect name=\"status\"\u003e\n    @foreach (UserStatusEnum::labels() as $value =\u003e $label)\n        \u003coption value=\"{{ $value }}\"\u003e\n            {{ $label }}\n        \u003c/option\u003e\n    @endforeach\n\u003c/select\u003e\n```\n\n## Testing\n\n``` bash\n$ composer lint\n$ composer test\n```\n\n## Security\n\nIf you discover any security related issues, please email inasyrov@ya.ru instead of using the issue tracker.\n\n## Credits\n\n- [Evgenii Nasyrov][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/nasyrov/laravel-enums.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/nasyrov/laravel-enums/master.svg?style=flat-square\n[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/nasyrov/laravel-enums.svg?style=flat-square\n[ico-code-quality]: https://img.shields.io/scrutinizer/g/nasyrov/laravel-enums.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/nasyrov/laravel-enums.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/nasyrov/laravel-enums\n[link-travis]: https://travis-ci.org/nasyrov/laravel-enums\n[link-scrutinizer]: https://scrutinizer-ci.com/g/nasyrov/laravel-enums/code-structure\n[link-code-quality]: https://scrutinizer-ci.com/g/nasyrov/laravel-enums\n[link-downloads]: https://packagist.org/packages/nasyrov/laravel-enums\n[link-author]: https://github.com/nasyrov\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnasyrov%2Flaravel-enums","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnasyrov%2Flaravel-enums","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnasyrov%2Flaravel-enums/lists"}