{"id":26099270,"url":"https://github.com/malusevdevelopment/laravel-pgenum","last_synced_at":"2026-04-24T09:32:06.099Z","repository":{"id":234805984,"uuid":"780953722","full_name":"MalusevDevelopment/laravel-pgenum","owner":"MalusevDevelopment","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-20T09:20:44.000Z","size":187,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-01T21:54:21.614Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MalusevDevelopment.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"github":["CodeLieutenant"],"ko-fi":"codelieutenant"}},"created_at":"2024-04-02T13:28:47.000Z","updated_at":"2024-10-21T14:44:16.000Z","dependencies_parsed_at":"2024-04-20T21:30:09.170Z","dependency_job_id":"0d1eb61b-759f-404d-b6f0-5c1525f31127","html_url":"https://github.com/MalusevDevelopment/laravel-pgenum","commit_stats":null,"previous_names":["codelieutenant/laravel-pgenum","malusevdevelopment/laravel-pgenum"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MalusevDevelopment%2Flaravel-pgenum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MalusevDevelopment%2Flaravel-pgenum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MalusevDevelopment%2Flaravel-pgenum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MalusevDevelopment%2Flaravel-pgenum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MalusevDevelopment","download_url":"https://codeload.github.com/MalusevDevelopment/laravel-pgenum/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242719299,"owners_count":20174530,"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":[],"created_at":"2025-03-09T16:30:45.509Z","updated_at":"2026-04-24T09:32:01.068Z","avatar_url":"https://github.com/MalusevDevelopment.png","language":"PHP","funding_links":["https://github.com/sponsors/CodeLieutenant","codelieutenant"],"categories":[],"sub_categories":[],"readme":"# Laravel Postgres Enums\n\n\u003e Laravel's answer to Postgres Real Enums\n\n[![Tests](https://github.com/CodeLieutenant/laravel-pgenum/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/CodeLieutenant/laravel-pgenum/actions/workflows/test.yml/badge.svg?branch=master)\n[![GitHub issues](https://img.shields.io/github/issues/CodeLieutenant/laravel-pgenum?label=Github%20Issues)](https://img.shields.io/github/issues/CodeLieutenant/laravel-pgenum?label=Github%20Issues)\n[![GitHub stars](https://img.shields.io/github/stars/CodeLieutenant/laravel-pgenum?label=Github%20Stars)](https://img.shields.io/github/stars/CodeLieutenant/laravel-pgenum?label=Github%20Stars)\n[![GitHub license](https://img.shields.io/github/license/CodeLieutenant/laravel-pgenum?label=Licence)](https://img.shields.io/github/license/CodeLieutenant/laravel-pgenum?label=Licence)\n![GitHub Sponsors](https://img.shields.io/github/sponsors/CodeLieutenant)\n![GitHub commit activity](https://img.shields.io/github/commit-activity/m/CodeLieutenant/laravel-pgenum)\n\n## Inspiration\n\nn Laravel’s migration, Enums already exist, yeah? Yes, but not quite. These Enums are not actual Database Enums.\nThese enums are just a string type with CHECK constraints.\nSo I said to myself, it would be really nice to use `real` Postgres enums in Laravel.\n\n## Getting started\n\n### Installing\n\n```shell\ncomposer require codelieutenant/laravel-pgenum\n```\n\n### Usage in Migrations\n\n##### Schema API\n\nThis library extends Laravel's `Illuminate\\Support\\Facades\\Schema` using `Illuminate\\Support\\Traits\\Macroable`\n\n```php\nSchema::createEnum(string $name, ?array $values = null);\nSchema::createEnumIfNotExists((string $name, ?array $values = null);\n\nSchema::addEnumValue(string $type, string $value, ?Direction $direction = null, ?string $otherValue = null, bool $ifNotExists = true);\nSchema::renameEnumValue(string $type, string $oldName, string $newName);\n\nSchema::dropEnum(string $name);\nSchema::dropEnumIfExists(string $name);\n```\n\nSchema API also works with PHP Enums by default\n\n```php\n\nenum MyEnum: string\n{\n    case MyValue = 'value';\n}\n\n// Migrations\n// Generated SQL\n// CREATE TYPE my_enum ENUM ('value');\nSchema::createEnum(MyEnum::class);\n\n// Generated SQL\n// CREATE TYPE my_enum ENUM ('value');\nSchema::dropEnum(MyEnum::class);\n```\n\n##### Blueprint API\n\nThere is only one function for Blueprint `enumeration` to create a column in table.\n\n```php\n// Accepts PHP Enums and Strings\n\\Illuminate\\Database\\Schema\\Blueprint::enumeration(string $name);\n```\n\n### Full Migration Example\n\n```php\n\npublic function up(): void\n{\n    // Postgres Enums must be known before Table is created\n    // This is my, `createEnum` must be seperated and before `Schema::create`\n    Schema::createEnum(MyEnum::class);\n    Schema::create('users', function(Blueprint $table) {\n        $table-\u003eid();\n        $table-\u003eenumeration(MyEnum::class);   \n    });\n}\n\npublic function down(): void\n{\n    Schema::dropEnum(MyEnum::class);\n}\n```\n\n### Using PHP Enums\n\nLaravel already supports PHP Enums by default, but\nthe nature of this library needs a bit more than what's\nprovided by Laravel by default.\nPHP Enums (in all forms -\u003e string/int backed, non-backed)\nare supported, here is the example:\n\n```php\n\nuse \\Illuminate\\Database\\Eloquent\\Model;\nuse \\CodeLieutenant\\LaravelPgEnum\\Casts\\EnumCast;\n\nenum Role : string\n{\n    case Admin = 'admin';\n    case User = 'user'; \n}\n\nclass User extends Model\n{\n    // For Laravel \u003c 11.0 use $casts property\n    public function casts(): array\n    {\n        return [\n            // This is supported by default\n            // as long as PHP Enum is backed by string\n            'role' =\u003e Role::class,\n            \n            // For non-backed/int backed PHP Enums\n            // custom converter is needed, this also\n            // can be applied to string backed enums (but not needed)\n            // This is due to the limitation of Postgres Enums\n            // as it requires values to be string named, and not INTs\n            // Using Role::class as example, can be any other PHP Enum\n            'non_string_backed_enum' =\u003e EnumCast::class ':' . Role::class\n        ];    \n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalusevdevelopment%2Flaravel-pgenum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalusevdevelopment%2Flaravel-pgenum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalusevdevelopment%2Flaravel-pgenum/lists"}