DEV Community

Ali Haider
Ali Haider

Posted on

Flexible Boolean Validation for Laravel

Laravel validation is powerful — but when working with APIs, boolean values can be messy.

❗ The Problem

Laravel’s default boolean validation does not handle string values like:

  • "true"
  • "false"

💡 The Solution

I created a Laravel package that adds flexible boolean validation.

✨ Supports:

  • true / false
  • 1 / 0
  • "1" / "0"
  • "true" / "false"

📦 Installation

composer require alihaider/flexible-boolean
Enter fullscreen mode Exit fullscreen mode

🚀 Usage

$request->validate([
    'status' => ['required', 'flexible_boolean']
]);
Enter fullscreen mode Exit fullscreen mode

🆚 Comparison

Feature Laravel Default This Package
Accept "true" string
Accept "false" string
Strict boolean validation
API-friendly

🎯 Why This Exists

In real-world APIs, data is not always clean.

This package ensures:
✔ consistency
✔ reliability
✔ developer simplicity


🔗 Packagist

https://packagist.org/packages/alihaider/flexible-boolean


💬 Feedback and contributions are welcome!

Top comments (0)