Laravel 11: Efficient Enum Creation (Command), Database Migrations, and Seeding Strategies
2 min readOct 15, 2024
Handling Empty Enum Creation with Artisan Commands
php artisan make:enum
Creating Enums: Organize in ‘Enums’ Folder for Better Management and Use Direct Commands
php artisan make:enum Enums/Role --string
Location: app/Enums/Role.php
<?php
namespace App\Enums;
enum Role: string
{
case ORGANIZER = 'organizer';
case ATTENDEE = 'attendee';
}
Use the make:enum
Artisan command with additional options, viewable by including the --help
flag for more details.
php artisan make:enum --help
How to Handle Enum Migrations with Updated Syntax
$table->enum('role', array_column(Role::cases(), 'value'))->default(Role::ATTENDEE->value);
After Change like that
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable()…