9 Steps to Connect Database to Laravel

Here are the 9 steps to connect your (MySql) Database to Laravel:

  • Step 1: First we have to create a database. So, we will start Apache and MySQL servers from XAMPP Control Panel.
  • Step 2: Open any web browser, like Chrome, and type localhost/phpmyadmin in URL.
  • Step 3: Now, click on the Databases tab and there, write the database named as sample and click on create.
  • Step 4: Now, you will have to find a file named .env, where you will have to specify the details for the MySQL server, like database name, username, etc. In that file, you will have to search for names starting with DB_.
  • Step 5: In that, you will find the DB_CONNECTION=mysql line. Below this are all the details specified for the database connection. You will have to specify the database name sample, that we created, after DB_DATABASE= and also specify username and password according to your need. Then save the file.
  • Step 6: Now, we will create a View in resources/views directory with the name demo.blade.php. Write the below code in the file.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Natali Dev

Natali Dev

Information Technology- Graduate