Just put that info in the migration? That's what they're acting as anyway.
Sep 28, 2014
9
Level 13
How to set a comment on table column using Schema Builder
I'd like to add comments on some table columns so I can re-think or communicate to other developers what is the concrete meaning on some unconcrete column names. In some big and long-living applications you can not modify the database schema so easy when modernizing only one part of the whole app. A comment is a suitable way I think.
Level 14
Hi @ipunkt, you could use the following comment property:
class CreateProductsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products', function(Blueprint $table)
{
$table->increments('id');
$table->string('product_name')->comment = "Product name column";
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('products');
}
}
It belongs to the MySQLGrammar class that you can find here:
<?php namespace Illuminate\Database\Schema\Grammars;
use Illuminate\Support\Fluent;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Blueprint;
class MySqlGrammar extends Grammar {
/**
* The possible column modifiers.
*
* @var array
*/
protected $modifiers = array('Unsigned', 'Nullable', 'Default', 'Increment', 'After', 'Comment');
I think you may use within table modifications as follow:
Schema::table('users', function($table)
{
$table->renameColumn('from', 'to')->comment = "New Comment of Product name column";
});
Hope it helps you.
4 likes
Please or to participate in this conversation.