PHPackages                             codelieutenant/laravel-pgenum - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. codelieutenant/laravel-pgenum

ActiveLibrary[Database &amp; ORM](/categories/database)

codelieutenant/laravel-pgenum
=============================

Postgres Enums used in Laravel Migrations

v1.1.0(3mo ago)52.2k↑725%1[1 issues](https://github.com/MalusevDevelopment/laravel-pgenum/issues)[11 PRs](https://github.com/MalusevDevelopment/laravel-pgenum/pulls)Apache-2.0PHPPHP &gt;=8.3CI passing

Since Apr 20Pushed 1w ago1 watchersCompare

[ Source](https://github.com/MalusevDevelopment/laravel-pgenum)[ Packagist](https://packagist.org/packages/codelieutenant/laravel-pgenum)[ GitHub Sponsors](https://github.com/CodeLieutenant)[ RSS](/packages/codelieutenant-laravel-pgenum/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (12)Versions (14)Used By (0)

Laravel Postgres Enums
======================

[](#laravel-postgres-enums)

> Laravel's answer to Postgres Real Enums

[![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)[![GitHub issues](https://camo.githubusercontent.com/3d035b1dea2713f62b2fb3fffd42d4c884c23fc6eaa087462a6a8bfa75a8a1a1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f436f64654c69657574656e616e742f6c61726176656c2d7067656e756d3f6c6162656c3d476974687562253230497373756573)](https://img.shields.io/github/issues/CodeLieutenant/laravel-pgenum?label=Github%20Issues)[![GitHub stars](https://camo.githubusercontent.com/570981f3d2ff5f684de6160863c394a06d1a8a108d2cc5ba9eca2f5784327755/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f436f64654c69657574656e616e742f6c61726176656c2d7067656e756d3f6c6162656c3d4769746875622532305374617273)](https://img.shields.io/github/stars/CodeLieutenant/laravel-pgenum?label=Github%20Stars)[![GitHub license](https://camo.githubusercontent.com/762c5a3e19b2381a53b109452216f1a4125d04619d46c067f10f5c3fad24617e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f436f64654c69657574656e616e742f6c61726176656c2d7067656e756d3f6c6162656c3d4c6963656e6365)](https://img.shields.io/github/license/CodeLieutenant/laravel-pgenum?label=Licence)[![GitHub Sponsors](https://camo.githubusercontent.com/63794fbc2a521225ee575aab250163c1ddab44724f2ade4ecbe2727c61a6f22a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73706f6e736f72732f436f64654c69657574656e616e74)](https://camo.githubusercontent.com/63794fbc2a521225ee575aab250163c1ddab44724f2ade4ecbe2727c61a6f22a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73706f6e736f72732f436f64654c69657574656e616e74)[![GitHub commit activity](https://camo.githubusercontent.com/5d5eb9ee091369a56a743f3bdcdb48149486f7820467a8c2b74ab3e29e688aa1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d69742d61637469766974792f6d2f436f64654c69657574656e616e742f6c61726176656c2d7067656e756d)](https://camo.githubusercontent.com/5d5eb9ee091369a56a743f3bdcdb48149486f7820467a8c2b74ab3e29e688aa1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d69742d61637469766974792f6d2f436f64654c69657574656e616e742f6c61726176656c2d7067656e756d)

Inspiration
-----------

[](#inspiration)

n Laravel’s migration, Enums already exist, yeah? Yes, but not quite. These Enums are not actual Database Enums. These enums are just a string type with CHECK constraints. So I said to myself, it would be really nice to use `real` Postgres enums in Laravel.

Getting started
---------------

[](#getting-started)

### Installing

[](#installing)

```
composer require codelieutenant/laravel-pgenum
```

### Usage in Migrations

[](#usage-in-migrations)

##### Schema API

[](#schema-api)

This library extends Laravel's `Illuminate\Support\Facades\Schema` using `Illuminate\Support\Traits\Macroable`

```
Schema::createEnum(string $name, ?array $values = null);
Schema::createEnumIfNotExists((string $name, ?array $values = null);

Schema::addEnumValue(string $type, string $value, ?Direction $direction = null, ?string $otherValue = null, bool $ifNotExists = true);
Schema::renameEnumValue(string $type, string $oldName, string $newName);

Schema::dropEnum(string $name);
Schema::dropEnumIfExists(string $name);
```

Schema API also works with PHP Enums by default

```
enum MyEnum: string
{
    case MyValue = 'value';
}

// Migrations
// Generated SQL
// CREATE TYPE my_enum ENUM ('value');
Schema::createEnum(MyEnum::class);

// Generated SQL
// CREATE TYPE my_enum ENUM ('value');
Schema::dropEnum(MyEnum::class);
```

##### Blueprint API

[](#blueprint-api)

There is only one function for Blueprint `enumeration` to create a column in table.

```
// Accepts PHP Enums and Strings
\Illuminate\Database\Schema\Blueprint::enumeration(string $name);
```

### Full Migration Example

[](#full-migration-example)

```
public function up(): void
{
    // Postgres Enums must be known before Table is created
    // This is my, `createEnum` must be seperated and before `Schema::create`
    Schema::createEnum(MyEnum::class);
    Schema::create('users', function(Blueprint $table) {
        $table->id();
        $table->enumeration(MyEnum::class);
    });
}

public function down(): void
{
    Schema::dropEnum(MyEnum::class);
}
```

### Using PHP Enums

[](#using-php-enums)

Laravel already supports PHP Enums by default, but the nature of this library needs a bit more than what's provided by Laravel by default. PHP Enums (in all forms -&gt; string/int backed, non-backed) are supported, here is the example:

```
use \Illuminate\Database\Eloquent\Model;
use \CodeLieutenant\LaravelPgEnum\Casts\EnumCast;

enum Role : string
{
    case Admin = 'admin';
    case User = 'user';
}

class User extends Model
{
    // For Laravel < 11.0 use $casts property
    public function casts(): array
    {
        return [
            // This is supported by default
            // as long as PHP Enum is backed by string
            'role' => Role::class,

            // For non-backed/int backed PHP Enums
            // custom converter is needed, this also
            // can be applied to string backed enums (but not needed)
            // This is due to the limitation of Postgres Enums
            // as it requires values to be string named, and not INTs
            // Using Role::class as example, can be any other PHP Enum
            'non_string_backed_enum' => EnumCast::class ':' . Role::class
        ];
    }
}
```

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance87

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 89.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~709 days

Total

2

Last Release

95d ago

PHP version history (2 changes)v1.0.0PHP &gt;=8.1

v1.1.0PHP &gt;=8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/33778979?v=4)[Dusan Malusev](/maintainers/CodeLieutenant)[@CodeLieutenant](https://github.com/CodeLieutenant)

---

Top Contributors

[![CodeLieutenant](https://avatars.githubusercontent.com/u/33778979?v=4)](https://github.com/CodeLieutenant "CodeLieutenant (17 commits)")[![zll600](https://avatars.githubusercontent.com/u/71714656?v=4)](https://github.com/zll600 "zll600 (2 commits)")

---

Tags

laravelpostgresenumspg-enumspostgres enums

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/codelieutenant-laravel-pgenum/health.svg)

```
[![Health](https://phpackages.com/badges/codelieutenant-laravel-pgenum/health.svg)](https://phpackages.com/packages/codelieutenant-laravel-pgenum)
```

###  Alternatives

[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k43.2M632](/packages/spatie-laravel-medialibrary)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M46](/packages/kirschbaum-development-eloquent-power-joins)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
