I need to make schema of postgres dynamic in laravel. The database config is below
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'stoddart'),
'username' => env('DB_USERNAME', 'postgres'),
'password' => env('DB_PASSWORD', '123456'),
'charset' => 'utf8',
'port' => env('DB_PORT', '7373'),
'prefix' => '',
'schema' => 'cp_bn',
],
Here you can see i have specified schema, but i want it to be Dynamic. The schema name will come from client side.
I am currently doing like following
$connection =DB::connection()->getPdo();
$connection->prepare("Set search_path to {$schema}")->execute();
But in this case i have to execute this whenever the connection to the database is made. I need to save it globally for all connection once it is set.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire