ItSolutionStuff.com

Laravel Migration Add Comment to Column Example

By Hardik Savani • April 16, 2024
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, laravel 10 and laravel 11 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

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel Migration Custom Index Name Example

Read Now →

Laravel Migration Custom Foreign Key Name Example

Read Now →

How to Add Index in Laravel Migration?

Read Now →

How to Add Foreign Key in Laravel Migration?

Read Now →

Laravel Migration - How to Add New Column in Existing Table ?

Read Now →

How to Change Table Name using Laravel Migration?

Read Now →

How to Remove Column from Table in Laravel Migration?

Read Now →

How to Change Column Name and Data Type in Laravel Migration?

Read Now →

How to Create Table using Migration in Laravel?

Read Now →

How to Drop Foreign Key Constraint in Laravel Migration?

Read Now →