How to get Database Name in laravel

To get Database Name in laravel, there are various ways, here are few of them you can found to get it easily in laravel.

Using Illuminate\Support\Facades\DB:

use Illuminate\Support\Facades\DB;

or

use DB;

$dbName = DB::connection()->getDatabaseName(); // return current active database name.

Using the Config files constants.

use Illuminate\Support\Facades\Config; 

or 

use Config; 

$dbconns = Config::get('database.connections'); // You can get your Databases list; 

$dbName = $dbconns['mysql']['database']; // Now You can also get your desired database names here  as I have get the mysql database name.

To get to know more about other Laravel topics, you can check these articles too.

Please follow and like us:

Related Posts

Leave a Reply

Share