PHPackages                             t-labs-co/booleanize - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. t-labs-co/booleanize

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

t-labs-co/booleanize
====================

Tools for easier boolean manipulation.

1.0.0(1y ago)23[4 PRs](https://github.com/T-Labs-Co/booleanize/pulls)MITPHPPHP ^8.4||^8.3||^8.2CI passing

Since Mar 18Pushed 2mo agoCompare

[ Source](https://github.com/T-Labs-Co/booleanize)[ Packagist](https://packagist.org/packages/t-labs-co/booleanize)[ Docs](https://github.com/t-labs-co/booleanize)[ GitHub Sponsors](https://github.com/ty-huynh)[ RSS](/packages/t-labs-co-booleanize/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (13)Versions (6)Used By (0)

Helper to work with Boolean in less pain way
============================================

[](#helper-to-work-with-boolean-in-less-pain-way)

[![Latest Version on Packagist](https://camo.githubusercontent.com/afb33ab1786f901024e4ca296ee6414b326f2c568235267f35a98a0bf2f050fb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f742d6c6162732d636f2f626f6f6c65616e697a652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/t-labs-co/booleanize)[![GitHub Tests Action Status](https://camo.githubusercontent.com/9cbfcaa1eeb002125cb9ede4b15a8ad45e886891e5b3099e63c47daa550b3199/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f742d6c6162732d636f2f626f6f6c65616e697a652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/t-labs-co/booleanize/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ca982ffbf75bcb7851e03bd7e6c8333d346a20348523b64d2c225f1ded83a2cc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f742d6c6162732d636f2f626f6f6c65616e697a652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/t-labs-co/booleanize/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/ebb60d7a1da2191f12ff4580d0e5821af6df07fc2f81a0b8650a5eabb864f654/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f742d6c6162732d636f2f626f6f6c65616e697a652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/t-labs-co/booleanize)

This package helps you deal with **Boolean value** in your laravel project, support action **cast model attribute, check value is true/false, convert to your desire boolean form**. It's super handy for keeping things clean and avoiding copy-paste, so you can grab what you need quickly and cut down on extra coding.

Work with us
------------

[](#work-with-us)

We're PHP and Laravel whizzes, and we'd love to work with you! We can:

- Design the perfect fit solution for your app.
- Make your code cleaner and faster.
- Refactoring and Optimize performance.
- Ensure Laravel best practices are followed.
- Provide expert Laravel support.
- Review code and Quality Assurance.
- Offer team and project leadership.
- Delivery Manager

PHP and Laravel Version Support
-------------------------------

[](#php-and-laravel-version-support)

This package supports the following versions of PHP and Laravel:

- PHP: `^8.2`
- Laravel: `^11.0`, `^12.0`

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require t-labs-co/booleanize
```

You can publish the config file with:

```
php artisan vendor:publish --tag="booleanize-config"
```

This is the contents of the published config file:

```
return [
// Override your configuration
];
```

Feature
-------

[](#feature)

- Check input value is `true` or `false`
- Convert input value to desired Boolean form
- Cast model attribute to correct value
- Query boolean field
- Validate rule for boolean field

Usage
-----

[](#usage)

#### Convert to bool with helper

[](#convert-to-bool-with-helper)

```
// use helper class
booleanize('true', null, true); // OUTPUT: true

// or call instance and using
booleanize()->convert('Yes', null, true); // OUTPUT: true
booleanize()->convert('Yes', null, 1); // OUTPUT: 1

booleanize()->convert('No', null, true); // OUTPUT: false
booleanize()->convert('No', null, 1); // OUTPUT: 0
```

#### Using in Model class

[](#using-in-model-class)

```
// model class

class User extends Authenticatable
{
    use HasBooleanizeTrait;

    // cast using
    protected function casts(): array
    {
        return [
            'agreed' => BooleanizeCast::class
        ];
    }

    // setting cast type SET and GET
    public function getTrueValueAs(): array
    {
        // config your default true value for your attribute when GET
        return [
            'agreed' => 1
        ];
    }

    public function setTrueValueAs(): array
    {
        // config your default true value for your attribute when SET
        return [
            'agreed' => 'yes'
        ];
    }
}

// query Scope using  whereBooleanize()
$users = User::whereBooleanize('agreed', true)->get();
// this will auto convert `true` to `yes` value from `setTrueValueAs()` and do query

// Or shorter
$users = User::whereBooleanizeTrue('agreed')->get();
```

#### Using in validate

[](#using-in-validate)

```
$data = [
    'term_confirm' => 'Y'
];
// term_confirm could be any in [y,yes,1,true]
$rules = [
    'term_confirm' => ['required', new BooleanizeTrueRule()],
];

Validator::validate($data, $rules, [
    'term_confirm' => 'Must confirm the term'
]);
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [T.Labs &amp; Co.](https://github.com/ty-huynh)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance67

Regular maintenance activity

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.5% 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

Unknown

Total

1

Last Release

472d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/201191860?v=4)[T.Labs &amp; Co.](/maintainers/t-labs-co)[@T-Labs-Co](https://github.com/T-Labs-Co)

---

Top Contributors

[![ty-huynh](https://avatars.githubusercontent.com/u/1597540?v=4)](https://github.com/ty-huynh "ty-huynh (10 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

booleanbooleanizeboolifylaravelpackagephpt-labs-colaravelbooleanize

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/t-labs-co-booleanize/health.svg)

```
[![Health](https://phpackages.com/badges/t-labs-co-booleanize/health.svg)](https://phpackages.com/packages/t-labs-co-booleanize)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

199.4k](/packages/tarfin-labs-event-machine)[tapp/filament-form-builder

User facing form builder using Filament components

132.4k3](/packages/tapp-filament-form-builder)

PHPackages © 2026

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