Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add comment to table (not column) in Laravel 5 migration?

How to add comment to table (ot column) in Laravel 5 migration?

I currently know how to add comment to column like:

$table->tinyInteger('status')->comment('0: requested; -1: rejected; 1:confirmed');

But what about table?

like image 789
mohsenJsh Avatar asked May 27 '16 22:05

mohsenJsh


People also ask

How do I add a column to a table in Laravel migration?

The Laravel migrations will use the Schema facade to create and modify database tables and columns: Schema::create('tasks', function (Blueprint $table) { $table->bigIncrements('id'); $table->timestamps(); }); Inside the facade, you could specify the different columns that you want to add.


2 Answers

Currently, Laravel does not allow (does not have functionality) to put comment on tables, so You have to use workaround in Your migration:

DB::statement("ALTER TABLE `<YOUR_TABLE>` comment '<COMMENT>'");
like image 117
Giedrius Kiršys Avatar answered Sep 19 '22 12:09

Giedrius Kiršys


For now there are no any option exist to add table comment like column add but then after you want to add the comment to table than you must have to use "DB" to add the comment to table.

For Example,

If you want to add the comment to website table then through below Syntax you can add the comment to table.

DB::select("ALTER TABLE website COMMENT = 'This table contains the website information for the application'");

NOTE: Before use above line you must have migrated website/ your table then n than you can use this.

like image 26
Chirag Viradiya Avatar answered Sep 23 '22 12:09

Chirag Viradiya