Laravel get connected database name example; In this tutorial, you will see how to check connected database name in laravel app. Here we will show you the database name which is connected to the current project, so you can easily get db name using DB Facade in laravel.
Let’s see the 2 examples to getting the current connected database name in laravel application.
Examplel 1:
Here the first example using DB connection to getDatabaseName() method;
public function getDatabaseName()
{
$dbName = \DB::connection()->getDatabaseName();
dd($dbName);
}
Example 2:
Sencondally we can check and get using config method.
public function getDatabaseName()
{
$dbName = Config::get('database.connections');
dd($dbName['mysql']['database']);
}
I hope its work for you.