Define default value for database column in Laravel 4

6

How can I add a default value for a column of my MySQL table through Laravel 4?

In SQL would be:

create table tabelaTeste(
    id int NOT NULL AUTO_INCREMENT,
    coluna1 varchar(50) DEFAULT valor,
    PRIMARY KEY(id));

In Laravel I am creating like this:

Schema::create('tabelaTeste', function ($table){
    $table->increments('id');
    $table->string('coluna1', '50');
});
    
asked by anonymous 23.11.2015 / 11:22

1 answer

3

It does this by calling the default method in a chained way:

Schema::create('tabelaTeste', function ($table){
    $table->increments('id');
    $table->string('coluna1', '50')->default('valor');
});
    
23.11.2015 / 12:12