1
votes

I am installing a new API with Laravel Passport using POSTGRESQL databases. When installing Laravel and basic authentication, it works ok to the point of registering users and logging in perfectly. (take the database ok, this is important!) But when following the steps to install Passport and run the "php artisan migrate" command, Passport does not recognize that I am using POSTGRESQL and looks for the connection to MYSQL, which is non-existent. I will appreciate ideas, I don't know what else to do.

ERROR:

Illuminate\Database\QueryException 

SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (SQL: 
create table `oauth_auth_codes` (`id` varchar(100) not null, `user_id` bigint unsigned not 
null, `client_id` bigint unsigned not null, `scopes` text null, `revoked` tinyint(1) not 
null, `expires_at` datetime null) default character set utf8mb4 collate 
'utf8mb4_unicode_ci')

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667|         // If an exception occurs when attempting to run a query, we'll format the 
error
668|         // message to include the bindings with SQL, which will make this exception a
669|         // lot more helpful to the developer instead of just the database's errors.
670|         catch (Exception $e) {
671|             throw new QueryException(
672|                 $query, $this->prepareBindings($bindings), $e
673|             );
674|         }
675| 

I try without result:

php artisan cache:clear
php artisan config:cache

My .ENV:

#DB_CONNECTION=mysql
#DB_HOST=127.0.0.1
#DB_PORT=3306
#DB_DATABASE=laravel
#DB_USERNAME=root
#DB_PASSWORD=

My CONFIG/DATABASE WITH POSTGRESQL:

'default' => env('DB_CONNECTION', 'pgsql'),

'connections' => [        

    'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'engine' => null,
        'options' => extension_loaded('pdo_mysql') ? array_filter([
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
        ]) : [],
    ],

    'pgsql' => [
        'driver' => 'pgsql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '5432'),
        'database' => env('DB_DATABASE', 'xxxx'),
        'username' => env('DB_USERNAME', 'xxxxxxxxxxx'),
        'password' => env('DB_PASSWORD', 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'),
        'charset' => 'utf8',
        'prefix' => '',
        'prefix_indexes' => true,
        'schema' => 'someschema',
        'sslmode' => 'prefer',
    ],
1

1 Answers

2
votes

I finally found the solution in a Laravel Passport forum, it seems that in the latest versions the connection to the db is configured directly in passport (I don't know why it doesn't take the one from .env or config / databases), "publishing" (exporting) from the I sell the connection file that includes the Passport Storage Driver to the app, to be able to modify it and declare the connection exclusively for Passport. Needless to say, there are 3 different places in Laravel to declare a connection to the database, subject to chatting directly with Otwell.

Anyway, this is done with the following command:

php artisan vendor:publish --tag=passport-config 

which adds a file in the config folder called passport.php, and where we find, ready to configure:

/*
|--------------------------------------------------------------------------
| Passport Storage Driver
|--------------------------------------------------------------------------
|
| This configuration options determines the storage driver that will
| be used to store Passport's data. In addition, you may set any
| custom options as needed by the particular driver you choose.
|
*/

'storage' => [
    'database' => [
        'connection' => env('DB_CONNECTION', 'mysql'),
    ],
],