如何使用Laravel Schema Builder在表上设置注释

如何使用Laravel Schema Builder在表上设置注释,laravel,comments,schema,Laravel,Comments,Schema,如何使用Laravel Schema Builder在表上设置注释 列集: public function up() { Schema::create('vendors', function (Blueprint $table) { $table->comment('not working - error'); // not working - error $table->increments('id'); $tabl

如何使用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();
    });
}

但是对于桌子呢?

嗯,我没有一个好的答案给你,但至少它是有效的

这是:

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语句。

我相信此功能已被提出,但被拒绝。可能被拒绝是因为SQL Server具有扩展属性,而其他数据库没有。非常好。这正是我想要的。但是如何发表评论是特定于司机的。这个答案说明了如果您使用的是MySQL,该如何做。使用Postgres,您必须将语法更改为
DB::statement(“表{$TABLE_name}上的注释是“我的注释”)
SQLite的注释不能用这样的查询设置,SqlServer完全是另一回事。@IGP laravel不提供在表上设置注释的接口,如果需要为不同的驱动程序设置注释,只需创建自己的表包装器可能更容易。获取当前的db驱动程序,并基于该驱动程序运行特定语句。有点<代码>开关((new\ReflectionClass(Schema::getConnection())->getShortName()){}这计算结果为
'PostgresConnection'
'MySqlConnection'
'SQLiteConnection'
'SqlServerConnection'
,允许我根据驱动程序生成不同的
DB::语句