How to Get Database Name in Laravel?

Hey Guys,

In this article, we will cover how to get database name in laravel. we will help you to give an example of laravel get database name. you can understand a concept of get database name in laravel. you will learn how to get eloquent database name in laravel.

You can use this example with laravel 6, laravel 7, laravel 8 and laravel 9 versions.

In this example, i will show you how to get database name in laravel. we will use getDatabaseName() function of DB class. so, let’s see the below example.

So, let’s see the below code:




namespace AppHttpControllers;

use IlluminateHttpRequest;

use DB;

class DemoController extends Controller



* Write code on Method


* @return response()


public function index(Request $request)


$database = DB::connection()->getDatabaseName();

dd("Your database is ".$database.".");




database is "my_database".

I hope it can help you….medrectangle-4-multi-155{border:none!important;display:block!important;float:none!important;line-height:0;margin-bottom:15px!important;margin-left:0!important;margin-right:0!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:300px;padding:0;text-align:center!important}

Leave a Comment