How to Create Table using Migration in Laravel?

Hello Developer,

In this tutorial, i will show you how to create new database table using migration command in laravel. We will look at example of how to create new table through migration in laravel. we will help you to give example of how to create new table migration in laravel. you will learn laravel create new table using migration. you will do the following things for create new table in laravel using migration.

I will guid you how to create new database table using laravel migration. we will use laravel command to creating miration for table. you can easily create new migration in laravel 6, laravel 7 and laravel 8.

I will also let you know how to this command follow this step by step run migration and rollback migration and how to create migration using command in laravel. let’s see bellow instruction.

Create Migration:

php artisan make:migration create_users_table

After run above command, you can see created new file as bellow and you have to add new column for string, integer, timestamp and text data type as like bellow wun this command:

database/migrations/2020_04_01_064006_create_posts_table.php

<?php
  
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
  
class CreateUserTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->Increments('id');
            $table->string('title');
            $table->text('body');
            $table->boolean('is_admin')->default(0);
            $table->timestamps();
        });
    }
  
    /**
     * Reverse the migrations.
     *
     * @return void
     */

    public function down()
    {
        Schema::dropIfExists('posts');
    }

}

Run Migration:

Using bellow run that command we can run our migration and create database table.

php artisan migrate

Create Migration with File Table:

php artisan make:migration create_users_table --table=users

Run Specific Migration Command:

php artisan migrate --path=/database/migrations/2021_12_28_064006_create_users_table.php

Migration Rollback:

I hope it can help you…

Leave a Comment