Back to articles
Flexible Boolean Validation for Laravel

Flexible Boolean Validation for Laravel

via Dev.to WebdevAli Haider

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 🚀 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!

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles