Sometimes we need to define boolean type in laravel migration. In this example, I will create a products table and I will create a field called "status" which type will be boolean. Using this status field, I will show you laravel migration boolean true false along with laravel migration boolean default value. So in this tutorial, I will show you laravel migration boolean default value.

Let's see the example code of laravel migration boolean true false:

<?php

use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->boolean('status');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
};

 

Now see the example code of laravel migration boolean default true:

<?php

use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->boolean('status')->default(true);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
};

 

Read also: Laravel Migration Add Index On Column Example

 

Conclusion

I have tried to discuss the clear concept of laravel migration true false. Now we know laravel migration boolean default value. Hope this laravel migration boolean true false tutorial will help you.