Laravel Tutorial Day 5

Learning Objectives: Understanding the use of MySQL Database using Laravel Migration. We will learn the process to create table using Migration in Laravel.

Step 1 : MySQL Database Connection Settings

Goto .env file and setup your mysql database name. First goto PHPMyadmin and create new database name as : db1 then in .env file update database name to db1

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db1
DB_USERNAME=root
DB_PASSWORD=

Now its time to run command and setup database Cache

php artisan config:Cache

Now its time to run laravel migration command:

php artisan migrate

Now lets create new migration page and we can create new table into our database. following command will create new file with name as products. In this file you can multiple fields as per your requirements. After your write down all the fields you need to run migrate command to update table.

php artisan make:migration create_products_table

Have you done adding new fields as follow into products:

 public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->string("name");
            $table->string("address");
            $table->timestamps();
        });
    }
php artisan migrate

if you want to reverse migration then you can use rollback commnd

php artisan migrate:rollback