Laravel Schema Builder,设置字段描述

ast*_*anu 3 laravel

是否可以使用laravel的架构生成器在sql字段中添加描述/注释。就像在drupal中一样?

小智 5

事实证明,您可以添加评论,但似乎没有记录在案。这篇Laracasts帖子展示了如何–通过在行尾添加“ comment”属性。

用他们的例子,

 Schema::create('products', function(Blueprint $table)
 {
    $table->increments('id');
    $table->string('product_name')->comment = "Product name column";
    $table->timestamps();
  });
 }
Run Code Online (Sandbox Code Playgroud)

事实证明-现在进行测试-您实际上可以使用更典型的函数语法,例如,

$table->string('product_name')->comment('Product name column');
Run Code Online (Sandbox Code Playgroud)

...类似于设置->default(...)->nullable()。有些人可能更喜欢这种样式以保持一致性。

从Laravel 5开始,使用MySQL似乎很有效。这可能是最近的改进。