PHPackages                             alihaider/flexible-boolean - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. alihaider/flexible-boolean

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

alihaider/flexible-boolean
==========================

Flexible boolean validation rule supporting true/false strings and values

v1.0.3(4mo ago)054MITPHPPHP &gt;=7.4

Since Mar 30Pushed 4mo agoCompare

[ Source](https://github.com/Alihaider8014/laravel-flexible-boolean)[ Packagist](https://packagist.org/packages/alihaider/flexible-boolean)[ RSS](/packages/alihaider-flexible-boolean/feed)WikiDiscussions main Synced 5d ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

Flexible Boolean for Laravel
============================

[](#flexible-boolean-for-laravel)

A powerful and flexible boolean validation rule for Laravel that supports real-world API and frontend inputs like `"true"` and `"false"`.

---

🚀 Why This Package Exists
-------------------------

[](#-why-this-package-exists)

Laravel's default `boolean` validation rule does NOT accept string values like:

- `"true"`
- `"false"`

However, in real-world applications (APIs, frontend forms, third-party integrations), boolean values are often sent as strings.

This package solves that problem by providing a **flexible and reliable boolean validation rule**.

---

✨ Features
----------

[](#-features)

- Supports:
    - `true` / `false`
    - `"true"` / `"false"`
    - `1` / `0`
    - `"1"` / `"0"`
- Laravel validation rule
- Helper methods for conversion
- Fully testable and production ready

---

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require AliHaider/laravel-flexible-boolean
```

⚙️ Service Provider
-------------------

[](#️-service-provider)

Laravel supports auto-discovery, so no manual registration is required.

If you are using an older Laravel version or need to register manually, add the service provider:

// config/app.php

```
'providers' => [
    AliHaider\FlexibleBoolean\FlexibleBooleanRuleServiceProvider::class,
];
```

✅ Usage
-------

[](#-usage)

### 1. Validation Rule

[](#1-validation-rule)

```
$request->validate([
    'is_active' => 'required|flexible_boolean'
]);
```

### 2. Using Rule Class

[](#2-using-rule-class)

```
use AliHaider\FlexibleBoolean\FlexibleBooleanRule;

$request->validate([
    'is_active' => ['required', new FlexibleBooleanRule()],
]);
```

### 3. Convert Value to Boolean

[](#3-convert-value-to-boolean)

```
use AliHaider\FlexibleBoolean\FlexibleBooleanRule;

FlexibleBooleanRule::toBoolean('true');  // true
FlexibleBooleanRule::toBoolean('false'); // false
FlexibleBooleanRule::toBoolean('1');     // true
FlexibleBooleanRule::toBoolean('0');     // false
```

⚖️ Comparison with Laravel Default
----------------------------------

[](#️-comparison-with-laravel-default)

FeatureLaravel DefaultThis PackageAccept `"true"` string❌ No✅ YesAccept `"false"` string❌ No✅ YesStrict boolean validation✅ Yes✅ YesAPI-friendly❌ Limited✅ Fully🧪 Example (Real-World API)
--------------------------

[](#-example-real-world-api)

```
POST /api/user

{
    "is_active": "true"
}
```

Validation:

```
$request->validate([
    'is_active' => 'required|flexible_boolean'
]);
```

###  Health Score

34

—

LowBetter than 74% of packages

Maintenance75

Regular maintenance activity

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

135d ago

PHP version history (2 changes)v1.0.0PHP &gt;=8.1

v1.0.2PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f0323f0399040f53ad9a745094b0e0bf91afea28cc91a9c2861f2264b006c46?d=identicon)[Alihaider8014](/maintainers/Alihaider8014)

---

Top Contributors

[![Alihaider8014](https://avatars.githubusercontent.com/u/49695554?v=4)](https://github.com/Alihaider8014 "Alihaider8014 (4 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/alihaider-flexible-boolean/health.svg)

```
[![Health](https://phpackages.com/badges/alihaider-flexible-boolean/health.svg)](https://phpackages.com/packages/alihaider-flexible-boolean)
```

###  Alternatives

[illuminate/validation

The Illuminate Validation package.

18838.8M2.0k](/packages/illuminate-validation)[sandermuller/laravel-fluent-validation

Fluent validation rule builders for Laravel

21428.9k6](/packages/sandermuller-laravel-fluent-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
