Laravel Migration Add Comment to Column Example
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
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Migration Custom Index Name Example
- Laravel Migration Custom Foreign Key Name Example
- How to Add Index in Laravel Migration?
- How to Add Foreign Key in Laravel Migration?
- Laravel Migration - How to Add New Column in Existing Table ?
- How to Change Table Name using Laravel Migration?
- How to Remove Column from Table in Laravel Migration?
- How to Change Column Name and Data Type in Laravel Migration?
- How to Create Table using Migration in Laravel?
- How to Drop Foreign Key Constraint in Laravel Migration?