Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
pgsql-enums-helpers
adonyarik/pgsql-enums
claude-code
migrations
schema
postgresql
postgres
enum
laravel

The EnumHelpers trait from adonyarik/pgsql-enums, which lists the cases of a PHP enum as names(), values() or a name => value toMap() map. Use when writing or changing a PHP enum in an app that has this package, or when an enum's cases are needed as a list, such as in validation rules, migrations, factories, seeders, form selects or API resources and documentation.

Install
php artisan boost:add-skill adonyarik/pgsql-enums

Save this content to: .claude/skills/pgsql-enums-helpers/SKILL.md

# EnumHelpers (adonyarik/pgsql-enums)

## When to use this skill

Use it when an enum's cases are needed as a plain array, or when creating an enum in an app that already uses the trait. The trait itself is `vendor/adonyarik/pgsql-enums/src/Traits/EnumHelpers.php`.

## Usage

```php
use Adonyarik\PgsqlEnums\Traits\EnumHelpers;

enum PostStatus: string
{
    use EnumHelpers;

    case Draft = 'draft';
    case Published = 'published';
}

PostStatus::names();  // ['Draft', 'Published']
PostStatus::values(); // ['draft', 'published']
PostStatus::toMap();  // ['Draft' => 'draft', 'Published' => 'published']
```

| Method | Returns |
| ------ | ------- |
| `names(): array` | Case names, as `list<string>` |
| `values(): array` | Backing values, as `list<int\|string>` |
| `toMap(): array` | Case names mapped to backing values, as `array<string, int\|string>` |

- All three are static and keep declaration order.
- The trait requires `cases()`, so it works in enums only: a class that uses it fails as soon as it is loaded.
- A pure enum (no backing type) has `names()` only: `values()` returns `[]` and `toMap()` throws a `LogicException`.
- Use the trait rather than writing `array_column(self::cases(), 'value')` by hand. When the app's enums already use it, add it to new enums too.

## Common uses

```php
// Validation: either works. Rule::enum also accepts ->only() and ->except()
'status' => ['required', Rule::in(PostStatus::values())],
'status' => ['required', Rule::enum(PostStatus::class)],

// Factory
'status' => fake()->randomElement(PostStatus::values()),

// Select options: value => name
array_flip(PostStatus::toMap());

// Native PostgreSQL ENUM type with the same values, in the migration that creates it.
// The ints of an int-backed enum are stored as strings.
$table->pgEnumColumnNew('status', 'post_status', PostStatus::values());
```

A migration that changes the values of an existing PostgreSQL type lists them literally instead, since the enum only knows its current cases. The `pgsql-enums-postgres-migrations` skill covers those migrations.

Laravel's `in:` rule string needs the values joined: `'in:'.implode(',', PostStatus::values())`. `Rule::in()` takes the array directly.

EnumHelpers (adonyarik/pgsql-enums)

When to use this skill

Use it when an enum's cases are needed as a plain array, or when creating an enum in an app that already uses the trait. The trait itself is vendor/adonyarik/pgsql-enums/src/Traits/EnumHelpers.php.

Usage

use Adonyarik\PgsqlEnums\Traits\EnumHelpers;

enum PostStatus: string
{
    use EnumHelpers;

    case Draft = 'draft';
    case Published = 'published';
}

PostStatus::names();  // ['Draft', 'Published']
PostStatus::values(); // ['draft', 'published']
PostStatus::toMap();  // ['Draft' => 'draft', 'Published' => 'published']
Method Returns
names(): array Case names, as list<string>
values(): array Backing values, as list<int|string>
toMap(): array Case names mapped to backing values, as array<string, int|string>
  • All three are static and keep declaration order.
  • The trait requires cases(), so it works in enums only: a class that uses it fails as soon as it is loaded.
  • A pure enum (no backing type) has names() only: values() returns [] and toMap() throws a LogicException.
  • Use the trait rather than writing array_column(self::cases(), 'value') by hand. When the app's enums already use it, add it to new enums too.

Common uses

// Validation: either works. Rule::enum also accepts ->only() and ->except()
'status' => ['required', Rule::in(PostStatus::values())],
'status' => ['required', Rule::enum(PostStatus::class)],

// Factory
'status' => fake()->randomElement(PostStatus::values()),

// Select options: value => name
array_flip(PostStatus::toMap());

// Native PostgreSQL ENUM type with the same values, in the migration that creates it.
// The ints of an int-backed enum are stored as strings.
$table->pgEnumColumnNew('status', 'post_status', PostStatus::values());

A migration that changes the values of an existing PostgreSQL type lists them literally instead, since the enum only knows its current cases. The pgsql-enums-postgres-migrations skill covers those migrations.

Laravel's in: rule string needs the values joined: 'in:'.implode(',', PostStatus::values()). Rule::in() takes the array directly.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package