Set default value for database column in Laravel 4

Asked

Viewed 1,113 times

6

How can I add a default value to a column of my Mysql table via 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’m creating like this:

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

1 answer

3


Does so by calling the default method in a chained form:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.