The default database connection defaults to _mysql_ connection even when the default is set to something else in _config/databases.php_ and do not have a connection named _mysql_.
This crashed my app after updating from v8 to v9. The upgrade guide does not mention this change.
Change the default database in _config/databases.php_ by changing line 18 to:
'default' => env('DB_CONNECTION', 'mydatabase'),
Rename _mysql_ connection to _mydatabase_.
This is due to this PR: https://github.com/laravel/passport/pull/1255/files#
And these changes:
https://github.com/cybercog/laravel-passport/blob/555e02c212022393888cbd4e902b327e9ec9ad7a/config/passport.php#L62
'storage' => [
'database' => [
'connection' => env('DB_CONNECTION', 'mysql'),
],
],
This code sets the default connection to 'mysql' if the environment variable does not exists. Completely ignoring the default connection set in _config/databases.php_
The model classes in passport were equipped with the following method:
public function getConnectionName()
{
return config('passport.storage.database.connection') ?? $this->connection;
}
This is somewhat useless in this scenario as config will return _mysql_ if the environment variable is not set and I do not override the config by exporting passport's config file.
I think it is bad practice to force the setting of DB_CONNECTION environment variable or setting default connection in two different files.
A possible solution could be the removal of the connection config from passports internal config file letting the getConnectionName method return $this->connection which will default to the connection set in _config/databases.php_
Just export the config file and set the default of the storage connection.
Just export the config file and set the default of the storage connection
how do that?
@rendo php artisan vendor:publish --tag=passport-config
Also ran into this after an upgrade. I agree with OP though - Passport should default to what is set at application level, and allow the option to specify an alternate if choosen.
Thanks for the tip. This should be noted in the upgrade guide IMO.
Most helpful comment
@rendo
php artisan vendor:publish --tag=passport-config