Support the ongoing development of Laravel.io →
posted 1 year ago
Artisan

Hello, good afternoon, I have a question about the correct way to work with different databases in the same project. for example I have: . BASE_01 . BASE_02, and in my config.database I have:.

'BASE_01' => [ 'driver' => 'sqlsrv', 'url' => env('DATABASE_URL'), 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '1433'), 'database' => 'BASE_01', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''),

     ],

     'BASE_02'=>[
         'driver' => 'sqlsrv',
         'url' => env('DATABASE_URL'),
         'host' => env('DB_HOST', 'localhost'),
         'port' => env('DB_PORT', '1433'),
         'database' => 'BASE_02',
         'username' => env('DB_USERNAME', 'forge'),
         'password' => env('DB_PASSWORD', ''),
       
     ],

and the db variable is saved in session, according to the session variable I make the query to the specific db. My question is, is there another way to do it or is what I'm doing right?

Last updated by @juanchos2018 1 year ago.
0

Are you trying to build a multi-tenant application? If so check this package out https://tenancyforlaravel.com/

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.