Specifying database credentials then setting a connection tenancy for Laravel

39 Views Asked by At

I have specified the connection name and password, however when I run the command it does not create a new connection

Illuminate\Database\QueryException

SQLSTATE[HY000] [1045] Access denied for user

Tenant::create([ 'tenancy_db_username' => 'foo', 'tenancy_db_password' => 'bar', ]);

I just want to create a name and password for each tenant db to monitor and control traffic

I Followed the Documentation Examples Here

I tried creating a default connection (it will be created by default) and it did not work.

1

There are 1 best solutions below

0
Alberto Moro On

It seems like you're encountering issues with database connection configuration. Firstly,

$tenant = Tenant::create();

can indeed be called without parameters, and it should connect and create a new database. It's advisable to check your .env file, especially the DB_CONNECTION parameter, to ensure it matches your database setup.

Additionally, please review the config/tenancy.php file, particularly the 'database' section, to ensure it's configured correctly. If everything looks fine there, double-check your database credentials to ensure they are correctly specified.