Laravel validation for boolean type fields

In this tutorial we will discuss laravel boolean type validation rule. How to validate a field value only accept boolean value.


Laravel validate boolean value

Laravel boolean validation rule accept only boolean type values like true, false, 1, 0, "1", and "0".

App/Http/Controllers/UserController.php
<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserController extends Controller
{
  public function store(Request $request) {
    $request->validate([
      'is_author' => 'required|boolean'
    ]);
  }
}

In above example is_author field only accept boolean(true, false, 1, 0, "1", and "0") values.

php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Random tutorial links