如何使用Laravel Schema Builder在表上设置注释 [英] How to set a comment on table using Laravel Schema Builder

查看:2513
本文介绍了如何使用Laravel Schema Builder在表上设置注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Laravel Schema Builder对表格设置注释?

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

列集合:

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();
    });
}

但是对于表?

推荐答案

好吧,我没有一个很好的答案,但至少它的工作原理。

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

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'");
}

只需在创建表之后添加一个DB语句。

Just add a DB statement after creating your table.

这篇关于如何使用Laravel Schema Builder在表上设置注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆