Skip to content

[13.x] Fix nested enum path duplication in make:enum#60210

Open
wbrasilsousa wants to merge 1 commit into
laravel:13.xfrom
wbrasilsousa:13.x
Open

[13.x] Fix nested enum path duplication in make:enum#60210
wbrasilsousa wants to merge 1 commit into
laravel:13.xfrom
wbrasilsousa:13.x

Conversation

@wbrasilsousa
Copy link
Copy Markdown

Summary

Fixes #60152make:enum produces incorrect nested paths when app/Enums directory exists.

The Bug

php artisan make:enum Enums/Profile/HairColor   # ✅ app/Enums/Profile/HairColor.php
php artisan make:enum Enums/Profile/EyeColor     # ❌ app/Enums/Enums/Profile/EyeColor.php

The first command creates the app/Enums directory. On the second command, getDefaultNamespace() detects the now-existing directory and prepends Enums\ to the namespace, doubling it with the user-provided Enums/ prefix.

The Fix

EnumMakeCommand::getDefaultNamespace() now checks whether the name input already starts with Enums/, Enums\, Enumerations/, or Enumerations\. When it does, the method returns the root namespace directly instead of prepending the directory-based sub-namespace.

Test Added

  • testItCanGenerateNestedEnumsWithoutPathDuplication — creates two nested enums sequentially and asserts both land in the correct directory without path duplication.

Closes #60152

When app/Enums directory exists, getDefaultNamespace() prepends Enums\
to the namespace. If user already includes Enums/ in the name arg,
the namespace gets doubled (App\Enums\Enums\Profile\).

This fix checks if input starts with Enums/ or Enums\ and skips
directory-based namespace resolution, preventing duplication.

Fixes laravel#60152
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.

Bad path for nested enums, created through artisan

1 participant