...

/

Comprehensive Guide to Laravel Migrations Setup and Implementation

Comprehensive Guide to Laravel Migrations Setup and Implementation

Learn about Laravel database setup, configuration, migrations, and modification.

Introduction to database setup in phpMyAdmin

Laravel supports multiple database management system (DBMS) connections. phpMyAdmin is a popular web-based administration tool used for managing and administering MySQL or MariaDB databases. It comes with a built-in installation of MySQL libraries. Both CLI and phpMyAdmin can opt to create a database.

Press + to interact
Preview of phpMyAdmin
Preview of phpMyAdmin

Overview of Laravel environment variables setup

In the Laravel framework, configuration settings are saved using environment variables in the .env file. These settings can change depending on where the application is being hosted. This allows developers to store sensitive information (such as email passwords), host database credentials, and other required configuration options. These configurations can be reused without writing them into our code. Laravel provides an .env file in the root directory. This file uses a format with KEY=VALUE syntax to assign values to global configuration-based variables. Here’s an example of a basic .env file:

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
............................
Preview of a Laravel .env file

After creating the database, the next step is to set up database configuration variables in the Laravel app. Laravel provides six environment variables to manage database-related configuration. The variables, along with their definitions, are given below:

  • DB_CONNECTION: This variable specifies the type of database we want to connect to. In this case, it’s set to MySQL, indicating that the application will connect to a MySQL database.

  • DB_HOST: This variable defines the host or IP address of the database server. The value 127.0.0.1 refers to the local machine, indicating that the database server is running on the same machine as the Laravel application.

  • DB_PORT: This variable specifies the port number on which the database server is listening. The value 3306 is the default port for MySQL.

  • DB_DATABASE: This variable specifies the name of the database we want to connect to. In this case, it’s set to Laravel.

  • DB_USERNAME: This variable represents the username used to authenticate and access the database ...