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. t-labs-co/booleanize

ActiveLibrary

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

Tools for easier boolean manipulation.

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

Since Mar 18Pushed 1mo 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 1mo ago

READMEChangelog (1)Dependencies (13)Versions (5)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

38

—

LowBetter than 85% of packages

Maintenance70

Regular maintenance activity

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

427d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b8096712a46f142a708061822c0644b806cd1000cb5499e408c6b11b12f6a899?d=identicon)[t-labs-co](/maintainers/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

[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2651.3M6](/packages/spatie-laravel-prometheus)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)[scalar/laravel

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[musahmusah/laravel-multipayment-gateways

A Laravel Package that makes implementation of multiple payment Gateways endpoints and webhooks seamless

852.2k1](/packages/musahmusah-laravel-multipayment-gateways)

PHPackages © 2026

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