Laravel Migration Add Comment to Column Tutorial

10-Apr-2023

.

Admin

Hi Guys,

Today, This blog 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.

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


<?php

use Illuminate\Database\Migrations\Migration;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Support\Facades\Schema;

class CreateProductsTable extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

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

$table->id();

$table->string('name');

$table->integer('amount')->comment("product amount detail");

$table->integer('stock');

$table->text('description');

$table->timestamps();

});

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

Schema::dropIfExists('products');

}

}

Existing Table Column with Comment

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('products', function (Blueprint $table) {

$table->string('stock')->comment("product stock detail")->change();

});

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

}

}

you can see preview:

It Will help You...

#Laravel 8

#Laravel