Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

jnoordsij
Copy link
Contributor

In #56271 support was added for resolving a database connection by passing an enum instead of a string to the connection method on the DatabaseManager class. This PR aims to make behavior more consistent in this class, by allowing the same enum to be passed to various other public methods when working with connections.

It also changes the following things:

  • make $name handling more consistent by using single line assign-and-use and null-coalescing operators instead of ternaries
  • remove $name null fallback from protected methods which have no default value and non-null docblock parameter typehint

@taylorotwell taylorotwell merged commit 1a3c942 into laravel:12.x Sep 2, 2025
65 checks passed
@jnoordsij jnoordsij deleted the allow-enum-databasemanager branch September 2, 2025 15:35
@tallenglish
Copy link

tallenglish commented Sep 3, 2025

Good Morning,

Pretty sure this update broke the database part for me - was working with 12.26.4 not with 12.27.0, very basic mariadb setup.

Found issue likely related to your update mentioned here, adding enum support.

Only thing not sure of, is what further up calls DatabaseManager->connection if it is supposed to give the default name, or if the default is to pick up via the config via getDefaultConnection.

Line 97 of DatabaseManager.php (in connection function)

$name = enum_value($name) ?? $this->getDefaultConnection()

Returns blank string, and it throws InvalidArgumentException "Database connection [] not configured", as the name is blank.

Change ?? to ?: though:

$name = enum_value($name) ?: $this->getDefaultConnection()

It returns the config default and works.

Guessing the enum_value is returning string, not null so null coalescing wont work here.

@tallenglish
Copy link

I also found leaving DatabaseManager as deployed you can fix the function enum_value

default match should be:

default => $value ?: value($default)

Rather than

default => $value ?? value($default)

@jnoordsij
Copy link
Contributor Author

Change ?? to ?: though:

$name = enum_value($name) ?: $this->getDefaultConnection()

It returns the config default and works.

Yeah I figure this 'fixes' the issue; suggested this at #56888 (comment). I still don't know why this is needed though.

Guessing the enum_value is returning string, not null so null coalescing wont work here.

It should not; enum_value should leave null untouched; everything basically should. My assumption is that $name is somehow already an empty string (passed as argument) in the call to connection and was previously converted just like null was.

Can you somehow check if indeed $name is indeed already '' before any logic happens within connection, and if so trace back where this value originates from? Maybe some config default? Or an empty value in .env?

@gabrielrbarbosa
Copy link
Contributor

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.

4 participants