Search code examples
laravel

Laravel Schema Builder, setting field description


Is it possible to add a description/comment to the sql field with laravel's schema builder. Just like in drupal?


Solution

  • It turns out that you can add comments, but it doesn't seem to be documented. This Laracasts post shows how – by adding a "comment" property to the end of the line.

    Using their example,

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

    As it turns out – just testing now – you can actually use the more typical function syntax for that, so for example,

    $table->string('product_name')->comment('Product name column');
    

    ...similar to setting ->default(...) or ->nullable(). Some people might prefer that style for consistency.

    This seems to work great as of Laravel 5 and using MySQL. It might be a recent improvement.