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.
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.
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.
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> |
cases(), so it works in enums only: a class that uses it fails as soon as it is loaded.names() only: values() returns [] and toMap() throws a LogicException.array_column(self::cases(), 'value') by hand. When the app's enums already use it, add it to new enums too.// 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.
How can I help you explore Laravel packages today?