How to Get Database Name in Laravel?
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:
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...
We are Recommending you
- Laravel - How to Get All Files in a Directory?
- How to Get All Routes in Laravel?
- Laravel Download File from URL to Storage Example
- How to Write Text on Existing PDF File in Laravel?
- How to Get Browser Name and Version in Laravel?
- How to Convert JSON to Array in Laravel?
- Laravel Cashier Stripe Subscription Example Tutorial
- How to Use Google Translator in Laravel?
- How to Automatically Generate Sitemap in Laravel?
- Laravel Contact Form Send Email Tutorial
- How to Add Google Map in Laravel?
- Laravel JQuery UI Autocomplete Ajax Search Example