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.0.0(2y ago)51.2k—0%1[1 issues](https://github.com/MalusevDevelopment/laravel-pgenum/issues)[1 PRs](https://github.com/MalusevDevelopment/laravel-pgenum/pulls)Apache-2.0PHPPHP &gt;=8.1CI failing

Since Apr 20Pushed 1mo 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 1mo ago

READMEChangelog (1)Dependencies (6)Versions (3)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

38

—

LowBetter than 85% of packages

Maintenance56

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

758d ago

### 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

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8703.0M17](/packages/yajra-laravel-oci8)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)

PHPackages © 2026

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