Skip to content

Conversation

@iamgergo
Copy link
Contributor

@iamgergo iamgergo commented Aug 6, 2025

This PR adds a small modification due to the enum method in migrations, to make the development a bit more streamlined.

enum Role: string
{
    case ADMIN = 'admin';
    case MEMBER = 'member';
}
// Before
Schema::create('users', static function (Blueprint $table): void {
    $table->enum('role', ['admin', 'member']);
});

// After
Schema::create('users', static function (Blueprint $table): void {
    $table->enum('role', Role::cases());
});

Normally this PR has no breaking change, since the enum_value works with non-enums as well, returning the original value.

Copy link
Contributor

@shaedrich shaedrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migrations are intended to be non-dependent on other application code that is prone to change as this may break the migration at a later date. So, this is probably not what most devs want. What would work better, though, would be kind of a stub that would prefill the migration with the hard-coded enum values from that point.

@iamgergo
Copy link
Contributor Author

iamgergo commented Aug 6, 2025

Migrations are intended to be non-dependent on other application code that is prone to change as this may break the migration at a later date. So, this is probably not what most devs want. What would work better, though, would be kind of a stub that would prefill the migration with the hard-coded enum values from that point.

I see this differently. There are already some methods  – like foreignIdFor(Model::class) – that depend on other part of the application. Also, at the end of the day the original way is still can be used if someone is afraid of breaking the code.

For me, the migrations are part of the same application as the enums or the models.

@taylorotwell taylorotwell merged commit b11b3c7 into laravel:12.x Aug 6, 2025
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants