How to Get Database Name in Laravel?
Hi Guys,
In this blog, I will show you get database name in laravel 6. we will give you the database name for the connected database, so you can use DB Facade in laravel.
if you do not know your database name then you can use bellow example.
Example 1
public function getDatabaseName()
{
$databaseName = \DB::connection()->getDatabaseName();
dd($databaseName);
}
Output
blog
Bellow example in Config Facade used to get connection database name.
Config in get() method used to get your connected database in laravel.
Example 2
public function getDatabaseName()
{
$databaseName = Config::get('database.connections.'.Config::get('database.default'));
dd($databaseName['database']);
}
Output
blog
Example 3
public function getDatabaseName()
{
$databaseName = Config::get('database.connections');
dd($databaseName['mysql']['database']);
}
Output
blog
It will help you...
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial