In this video i will talk about Database Connection in Laravel and you will get to know How to connect a database in Laravel.
Laravel makes connecting with databases and running queries extremely simple. The database configuration file is app/config/database.php. In this file you may define all of your database connections, as well as specify which connection should be used by default. Examples for all of the supported database systems are provided in this file.
Currently Laravel supports four database systems: MySQL, Postgres, SQLite, and SQL Server.
Connecting your laravel project to MySQL database is moderately easy. Since we have done the installation with XAMPP. It comes along with already installed MySQL and PHPMyAdmin. In this tutorial, I will make use of phpMyAdmin to create a new database that will connect to the laravel application. This post is assuming you already have a laravel project setup in your local and you are able to access its homepage via localhost or custom set domain name.
Step1: Create a new database via phpmyadmin
Navigate to domain name.dev/ PHPMyAdmin, Click on the Databases tab and create a new database with your wanted name.
Clicking on create will create a new database in your XAMPP MySQL.
Step2: Changes in.env configuration file
Once the database is created, you need to tell your laravel project the details about the database.
Laravel 5 has a pretty simple way to do that, All configuration that you should stay private and should not share goes into the .env file of your laravel project.
DB_CONNECTION=mysql
DB_HOST=190.0.0.1
DB_PORT=4008
DB_DATABASE=testProject
DB_USERNAME=root
DB_PASSWORD=
Modify the following property in your .env file according to your database settings.