{"id":15027297,"url":"https://github.com/kongulov/interact-with-enum","last_synced_at":"2025-04-09T20:21:55.687Z","repository":{"id":177018400,"uuid":"659831083","full_name":"kongulov/interact-with-enum","owner":"kongulov","description":"Trait for convenient use of ENUM in PHP","archived":false,"fork":false,"pushed_at":"2025-04-04T19:18:05.000Z","size":14,"stargazers_count":26,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-04T20:24:58.064Z","etag":null,"topics":["enum","enums","laravel","php","php81"],"latest_commit_sha":null,"homepage":"https://kongulov.dev/blog/simplifying-data-structures-with-enum-in-laravel","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/kongulov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"kongulov","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"custom":null}},"created_at":"2023-06-28T16:48:21.000Z","updated_at":"2025-04-04T19:17:21.000Z","dependencies_parsed_at":"2025-02-15T20:33:20.965Z","dependency_job_id":"11ae2a26-8f45-4338-a1d3-4b7a0c14f75d","html_url":"https://github.com/kongulov/interact-with-enum","commit_stats":null,"previous_names":["kongulov/interact-with-enum"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kongulov%2Finteract-with-enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kongulov%2Finteract-with-enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kongulov%2Finteract-with-enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kongulov%2Finteract-with-enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kongulov","download_url":"https://codeload.github.com/kongulov/interact-with-enum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248104555,"owners_count":21048359,"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","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","enums","laravel","php","php81"],"created_at":"2024-09-24T20:06:09.287Z","updated_at":"2025-04-09T20:21:55.674Z","avatar_url":"https://github.com/kongulov.png","language":"PHP","readme":"# Interact With Enum in PHP\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/kongulov/interact-with-enum?style=flat-square)](https://packagist.org/packages/kongulov/interact-with-enum)\n![Licence](https://img.shields.io/github/license/kongulov/interact-with-enum?style=flat-square)\n[![Total Downloads](https://poser.pugx.org/kongulov/interact-with-enum/downloads?format=flat-square)](https://packagist.org/packages/kongulov/interact-with-enum)\n\nThis package contains the `InteractWithEnum.php` trait, which you can use to conveniently work with ENUMs.\n\n## Requirements\n\n- `php: \u003e=8.1`\n\n## Installation\n\nInstall the package via Composer:\n\n```bash\n# Install interact-with-enum\ncomposer require kongulov/interact-with-enum\n```\n\n## Usage\n\nImagine you have ENUM `StatusEnum.php` where we already use the `InteractWithEnum` trait:\n\n```php\n\u003c?php\n\nnamespace App\\Enums;\n\nuse Kongulov\\Traits\\InteractWithEnum;\n\nenum StatusEnum: string {\n    use InteractWithEnum;\n\n    case Pending = 'pending';\n    case Active = 'active';\n    case Inactive = 'inactive';\n}\n```\n\n### After using the trait, you can call methods:\n\n* **names()**\n```php\nStatusEnum::names()\n```\nReturn:\n\u003cpre\u003e\narray:3 [\n  0 =\u003e \"Pending\"\n  1 =\u003e \"Active\"\n  2 =\u003e \"Inactive\"\n]\n\u003c/pre\u003e\n\n\u003chr\u003e\n\n* **values()**\n```php\nStatusEnum::values()\n```\nReturn:\n\u003cpre\u003e\narray:3 [\n  0 =\u003e \"pending\"\n  1 =\u003e \"active\"\n  2 =\u003e \"inactive\"\n]\n\u003c/pre\u003e\n\n\u003chr\u003e\n\n* **array()**\n```php\nStatusEnum::array()\n```\nReturn:\n\u003cpre\u003e\narray:3 [\n  \"pending\" =\u003e \"Pending\"\n  \"active\" =\u003e \"Active\"\n  \"inactive\" =\u003e \"Inactive\"\n]\n\u003c/pre\u003e\n\n\u003chr\u003e\n\n* **find($needle)**\n```php\nStatusEnum::find('Active') // Find by name\nStatusEnum::find('active') // Find by value\n```\nReturn:\n\u003cpre\u003e\nApp\\Enums\\StatusEnum {\n  name: \"Active\"\n  value: \"active\"\n}\n\u003c/pre\u003e\n\n\u003chr\u003e\n\n* **count()**\n```php\nStatusEnum::count()\n```\nReturn:\n\u003cpre\u003e\n3\n\u003c/pre\u003e\n\n\u003chr\u003e\n\n* **exists($value)**\n```php\nStatusEnum::exists('active')\n```\nReturn:\n\u003cpre\u003e\ntrue\n\u003c/pre\u003e\n\n\u003chr\u003e\n\n* **getByIndex($index)**\n```php\nStatusEnum::getByIndex(1)\n```\nReturn:\n\u003cpre\u003e\nApp\\Enums\\StatusEnum {\n  name: \"Active\"\n  value: \"active\"\n}\n\u003c/pre\u003e\n","funding_links":["https://github.com/sponsors/kongulov"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkongulov%2Finteract-with-enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkongulov%2Finteract-with-enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkongulov%2Finteract-with-enum/lists"}