Laravel Migration Add Comment to Column Example

By Hardik Savani November 5, 2023 Category : Laravel

This article is focused on laravel migration add comment to table. This tutorial will give you simple example of laravel migration add comment to table. i would like to show you laravel migration add comment to existing column. This post will give you simple example of laravel migration add comment to existing column. Let's see bellow example laravel migration add comment to table.

laravel migration provide comment() where you can add comment to table column. so let's see both example. you can easily set with laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10 version.

so let's see bellow simple examples:

Create Table Column with Comment

<?php

use Illuminate\Database\Migrations\Migration;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Support\Facades\Schema;

class CreatePostsTable extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

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

$table->id();

$table->string('first_name');

$table->string('last_name');

$table->string('email');

$table->string('visits')->comment("number of visit counter");

$table->timestamps();

});

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

Schema::dropIfExists('posts');

}

}

Existing Table Column with Comment

<?php

use Illuminate\Database\Migrations\Migration;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Support\Facades\Schema;

class AddNewColumnAdd2 extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

Schema::table('patients', function (Blueprint $table) {

$table->string('email')->comment("patient email address")->change();

});

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

}

}

you can see preview:

you can use as you need.

i hope it can help you...

Shares