17

This is my current code.

public function up()
{
    Schema::table('render', function (Blueprint $table) {
        $table->boolean('displayed')->default(1);
    });
}`

How to change the default value to 0 as below?

public function up()
{
    Schema::table('render', function (Blueprint $table) {
        $table->boolean('displayed')->default(0);
    });
}
3
  • So, what is your question? Commented Apr 24, 2018 at 7:23
  • 2
    how to change the default value to default(0); Commented Apr 24, 2018 at 7:31
  • Does this answer your question? Laravel migrations change default value of column Commented Apr 5, 2021 at 14:49

2 Answers 2

39
public function up()
{
    Schema::table('render', function (Blueprint $table) {
        $table->boolean('displayed')->default(0)->change();
    });
}

Added ->change(). Please see Link

Sign up to request clarification or add additional context in comments.

Comments

1
Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->boolean('is_active')->unsigned()->nullable();
    $table->timestamps();
});

is_active column is defined as a nullable boolean column using the boolean data type and the unsigned modifier. This will allow you to use the true and false keywords in your database queries instead of 0 and 1.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.