Laravel Migration Add Comment to Column Example

In this example we will show Laravel Migration Add Comment to Column Example. we will explain laravel migration add comment to table. In this blog we focused on laravel migration add comment to table. This tutorial you learn simple example of laravel migration add comment to table.

I would such as to show you laravel migration add comment to existing column. In this post will give you simple example of laravel migration add comment to existing column.

Laravel migration provide comment() where you can add comment to table column. so let’s see both example. you can easily set laravel 8 version.

Create Table Column with Comment

In this step we will create migration and add comment to column in table. In this example we will create posts migration using the following command.
php artisan make:migration posts
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class Posts extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->text('description');
            $table->integer('status')->comment("1 = Active and 0 = Inactive");
            $table->timestamps();
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
}

After enter the following command to create table.

php artisan migrate

Existing Table Column with Comment

In this step we will  add comment to existing column. Before change a column, you must install the doctrine/dbal package using the Composer package manager.

composer require doctrine/dbal
php artisan make:migration add_comment_to_posts_table
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddCommentToPostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('posts', function (Blueprint $table) {
            $table->text('description')->comment("Write your post description")->change();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('posts', function (Blueprint $table) {
            //
        });
    }
}

Laravel Migration Add Comment to Column Example

I hope you understand of Laravel Migration Add Comment to Column and it can help you…