How To Create Table Migration In Laravel 8?

10-Apr-2023

.

Admin

Hi Guys,

In this example,I will learn you how to create table migration in laravel 8.you can easy and simplay create table migration in laravel 8. you will learn laravel create table using migration. you will do the following things for create table in laravel using migration.

I will also let you know how to run migration and rollback migration and how to create migration using command in laravel 8. let's see bellow instruction.

Create Migration:


Using bellow command you can simply create migration for database table.

php artisan make:migration create_posts_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:

database/migrations/2020_04_01_064006_create_posts_table.php

<?php

use Illuminate\Database\Migrations\Migration;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Support\Facades\Schema;

class CreatePostTable extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

Schema::create('posts', function (Blueprint $table) {

$table->id();

$table->string('name');

$table->text('dec');

$table->longText('party_name')->nullable();

$table->integer('votes');

$table->tinyInteger('votes')->default(0);

$table->boolean('confirmed');

$table->timestamps();

});

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

Schema::dropIfExists('posts');

}

}

Run Migration:

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

php artisan migrate

Create Migration with Table:

php artisan make:migration create_posts_table --table=posts

Migration Rollback:

php artisan migrate:rollback

It will help you...

#Laravel 8

#Laravel 7

#Laravel

#Laravel 6