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 / false1 / 0"1" / "0""true" / "false"
📦 Installation
composer require alihaider/flexible-boolean
🚀 Usage
$request->validate([
'status' => ['required', 'flexible_boolean']
]);
🆚 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)