How to set a comment on table using Laravel Schema

2019-03-24 14:39发布

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?

1条回答
欢心
2楼-- · 2019-03-24 15:20

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.

查看更多
登录 后发表回答