Tutorialsplane

Laravel Create Table Using Migration


Laravel Create Table Using Migration – The Laravel Create Table Using Migration is used to create a database table using migration from artisan command.


Laravel Create Table Using Migration | with full Example.

Let us understand how to use Laravel Create Table Using Migration.

Full example of create table using migration.

Now here i am going to explain how to create table step by step.

First we have to create migration using artisan command like this.

php artisan make:migration createDataTable

After run this command we can check migration automatically created at databse/migration/fileName.

Migration file:-

Let’s look at a simple example.

<?php use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{ 
    public function up()
    {
        Schema::create('sonu', function (Blueprint $table) {
            $table-?>increments('id');
            $table->string('name');
            $table->string('email');
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

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

Then Run the migrate command in command prompt:-

php artisan migrate

Now we can see table will be created in your database.

Laravel Tutorial