How To Add Laravel into Database in a simple process 2023

Learn how to add a database to Laravel. We can use SQLite if we want. It is connected to Laravel by default. We can use any other database if we want. I will show you how to add MySQL. To add a database, MySQL must be installed on our computer. I will be using WAMP server. It has a package of php, MySQL etc as one. There is another useful tool - phpMyAdmin. phpMyAdmin is a great tool.

Laravel
Laravel

Laravel has a database configuration file named .env. We must provide our database name, host, password, etc. in the profile.

Using phpMyAdmin you can create a database and post information here. You can also use the command line if you like. To create a MySQL database using the command line, you need to add the path to mysql to your Windows environment variable. If you are using wamp the mysql path will be: C:\wamp\bin\mysql\mysql6.x.x\bin

To create a database on the command line, first login to mysql with a username and password. For example, to log in as root user:

mysql -uroot -p

Then to create the database:

create database database-name;

If the database will be created in the name you specified.

We can query this database. First of all, I want to query this database, I have to choose. For him:

mysql use database name

We can then use any SQL command. See http://www.w3schools.com/sql/ for basic SQL.

Creating a database using the command line will work, but will also work with creating a database using phpMyAdmin. An additional feature of phpMyAdmin is that the tables and database contents are viewed visually and can be edited or added to.

First of all, database basics. Return to Laravel. Change to our project directory on the command line. Then write the following command

php artisan migration

With a proper connection to our database, some tables will be added to the database. Go to mysql show tables; [Jump to semicolon] or go to phpMyAdmin and see the database.

The command we have run is to work on how the database database is deployed in how the database tables are created. And what the database schemas will be is written in the Project > Database > Migrations folder. If we go into this folder, we will see that there are two files inside it. One for the user table. Another password for the table.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.