In this tutorial, we are going to configure the database in Laravel 5.8 application which we have just installed. If you did not installed
- SQL Server
Laravel comes with
config/database.php file where we are able to configure our database.
'mysql' => [ 'read' => [ 'host' => '192.168.1.1', ], 'write' => [ 'host' => '126.96.36.199' ], 'driver' => 'mysql', 'database' => 'database', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ],
There are couple of scenario when we need to use different database connection for different operation. As shown in above configuration code Laravel gives out of the box solution to achieve our goal.
As shown in config file we can configure one database connection for
We are using driver
'driver' => 'mysql', ‘database’ => ‘YOURDATABASENAME’, ‘username’ => ‘YOURMYSQLUSERNAME’, Default username is root is most of the cases. ‘password’ => ‘YOURMYSQLPASSWORD’.
If you have come across the situation where you need to use multiple databases then we can achieve that too with the same config file. you can take a look into our tutorial for configuring multiple databases in Laravel.