Cara Membuat Table Untuk Laravel

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\Support\Facades\Schema;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Database\Migrations\Migration;

class CreatePostsTable extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

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

$table->bigIncrements('id');

$table->string('title');

$table->text('body');

$table->boolean('is_publish')->default(0);

$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

After that you can see created new table in your database as like bellow:

Create Migration with Table:

php artisan make:migration create_posts_table --table=posts

Run Specific Migration:

php artisan migrate --path=/database/migrations/2020_04_01_064006_create_posts_table.php

Sumber : https://www.itsolutionstuff.com/post/how-to-create-table-using-migration-in-laravelexample.html