{"id":28003183,"url":"https://github.com/atomjoy/laravel-enum","last_synced_at":"2025-10-12T05:11:58.457Z","repository":{"id":290744749,"uuid":"975429891","full_name":"atomjoy/laravel-enum","owner":"atomjoy","description":"Laravel enum examples.","archived":false,"fork":false,"pushed_at":"2025-04-30T10:20:45.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-09T01:59:34.365Z","etag":null,"topics":["laravel-enum"],"latest_commit_sha":null,"homepage":"https://github.com/atomjoy/laravel-enum/tree/main","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atomjoy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"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,"zenodo":null}},"created_at":"2025-04-30T09:50:36.000Z","updated_at":"2025-04-30T10:20:49.000Z","dependencies_parsed_at":"2025-04-30T11:31:53.324Z","dependency_job_id":"9c123a37-0288-4308-9631-926c53de44b1","html_url":"https://github.com/atomjoy/laravel-enum","commit_stats":null,"previous_names":["atomjoy/laravel-enum"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/atomjoy/laravel-enum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomjoy%2Flaravel-enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomjoy%2Flaravel-enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomjoy%2Flaravel-enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomjoy%2Flaravel-enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atomjoy","download_url":"https://codeload.github.com/atomjoy/laravel-enum/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomjoy%2Flaravel-enum/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010342,"owners_count":26084738,"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-10-12T02:00:06.719Z","response_time":53,"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":["laravel-enum"],"created_at":"2025-05-09T01:59:33.306Z","updated_at":"2025-10-12T05:11:58.440Z","avatar_url":"https://github.com/atomjoy.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# laravel-enum\nLaravel enum examples.\n\n## Roles\n\n```php\n\u003c?php\n\nnamespace App\\Enums\\Spatie;\n\nenum RolesEnum: string\n{\n    case ADMIN = 'admin';\n    case WRITER = 'writer';\n    case SUPERADMIN = 'super_admin';\n\n    public function label(): string\n    {\n        return match ($this) {\n            static::ADMIN =\u003e 'Admins',\n            static::WRITER =\u003e 'Writers',\n            static::SUPERADMIN =\u003e 'Super Admins',\n            default =\u003e throw new \\Exception('Unknown enum value requested for the label.'),\n        };\n    }\n}\n```\n\n## Use\n\n```php\n\u003c?php\n\n$role = RolesEnum::ADMIN-\u003evalue;\n$label = RolesEnum::ADMIN-\u003elabel();\n\n$roles = RolesEnum::cases();\n\nforeach (RolesEnum::cases() as $item) {\n    Role::create(['name' =\u003e $item-\u003evalue, 'guard_name' =\u003e 'web']);\n}\n\n// Invalid data throws error\n$role = RolesEnum::from('admin');\n\nvar_dump($role); // enum(RolesEnum::ADMIN)\necho $role-\u003ename; // \"ADMIN\";\necho $role-\u003evalue; // \"admin\"\n\n// Invalid data return null\n$role = RolesEnum::tryFrom('not-existing');\n\nvar_dump($role); // null\n```\n\n## Casts\n\n```php\nprotected $casts = [\n    'user_role' =\u003e \\App\\Enums\\RolesEnum::class\n];\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomjoy%2Flaravel-enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatomjoy%2Flaravel-enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomjoy%2Flaravel-enum/lists"}