Skip to content

[13.x] Fix DB::setDefaultConnection() storing enums in the configuration - #61810

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
ahmadreza-fatemikia:fix-db-default-connection-enum
Oct 2, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
ahmadreza-fatemikia:fix-db-default-connection-enum

Conversation

@ahmadreza-fatemikia

Copy link
Copy Markdown
Contributor

DatabaseManager::connection(), purge(), disconnect(), reconnect() and usingConnection() all accept enums, but setDefaultConnection() stores the given value in the configuration as-is. When it receives an enum, the enum instance is written to database.default, and every subsequent query on the default connection fails:

enum Connection: string
{
    case Reporting = 'reporting';
}

DB::setDefaultConnection(Connection::Reporting);

DB::table('users')->get();
// TypeError: str_ends_with(): Argument #1 ($haystack) must be of type string, Connection given

This PR normalizes the name using enum_value(), matching the setDefaultDriver() methods of the other managers (AuthManager, CacheManager, MailManager, QueueManager, LogManager, etc.), and adds tests for both backed and unit enums.

@taylorotwell
taylorotwell merged commit 3f0cdf2 into laravel:13.x Oct 2, 2026
62 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.

2 participants