Laravel Migration Add Comment to Column Example

By Hardik Savani | April 24, 2021 | 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 and laravel 8 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...




Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: