A Laravel package to automatically generate PHP enums from database columns.
composer require mattyeend/dynamic-enum-generatorThis package supports Laravel 10, 11, and 12.
Laravel will auto-discover the service provider.
Generate an enum from a specific table and column:
php artisan enum:generate --table=users --column=status--table: The database table name.--column: The column name to generate the enum from.--path: Path where enums are saved (default:app/Enums).
Suppose you have a users table with a status column containing:
activeinactivepending
Running:
php artisan enum:generate --table=users --column=statusGenerates app/Enums/Status.php:
<?php
namespace App\Enums;
enum Status: string
{
case ACTIVE = 'active';
case INACTIVE = 'inactive';
case PENDING = 'pending';
}- Works with any table and column
- Creates directories automatically if missing
- Generates native PHP 8.1+ enums
- Perfect for status, role, type fields, etc.
This package is licensed under the MIT License.
Feel free to fork the repository and submit pull requests for improvements or new features!