Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a comment on table using Laravel Schema Builder

Tags:

How to set a comment on table using Laravel Schema Builder?

Column set:

public function up() {     Schema::create('vendors', function (Blueprint $table)      {         $table->comment('not working - error'); // not working - error         $table->increments('id');         $table->string('vendor', 255)->comment('Some comment.');         $table->timestamps();     }); } 

But for the table?

like image 815
Andris Briedis Avatar asked Dec 14 '15 16:12

Andris Briedis


People also ask

What is schema builder in Laravel?

The Laravel Schema class provides a database agnostic way of manipulating tables. It works well with all of the databases supported by Laravel, and has a unified API across all of these systems.

What is foreign key in Laravel?

A foreign key is a field that is used to establish the relationship between two tables via the primary key (You can also use a non-primary field but not recommended). In this tutorial, I show how you can add a foreign key constraint while creating a table using migration in the Laravel 9 project.

How do I change the data type in Laravel migration?

How to change data type of column in laravel 9 migration ? Step 1 : Install doctrine/dbal package. Step 2 : Generate migration file. Step 3 : Open generated migration file and update.


1 Answers

Well I don't have a nice answer for you, but at least it works.

Here it is:

public function up() {     $tableName = 'vendors';      Schema::create($tableName, function (Blueprint $table)      {         $table->increments('id');         $table->string('vendor', 255)->comment('Some comment.');         $table->timestamps();     });      DB::statement("ALTER TABLE `$tableName` comment 'My comment'"); } 

Just add a DB statement after creating your table.

like image 105
Fabio Antunes Avatar answered Nov 04 '22 01:11

Fabio Antunes