PHPackages                             laragear/compare - 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. laragear/compare

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

laragear/compare
================

Small utility trait to fluently compare object values.

v1.1.0(3y ago)6159MITPHPPHP 8.\*

Since Jul 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Laragear/Compare)[ Packagist](https://packagist.org/packages/laragear/compare)[ Fund](https://github.com/sponsors/DarkGhostHunter)[ Fund](https://paypal.me/darkghosthunter)[ RSS](/packages/laragear-compare/feed)WikiDiscussions 1.x Synced today

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Modern PHP has very flexible Comparison Operators, so this package is no longer needed.
=======================================================================================

[](#modern-php-has-very-flexible-comparison-operators-so-this-package-is-no-longer-needed)

---

Comparable
==========

[](#comparable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ca41d1e381fc7a7ae695d745d1a2a2a1c6cb8b646f5afbf49e193553c3ab3daf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c617261676561722f636f6d706172652e737667)](https://packagist.org/packages/laragear/compare)[![Latest stable test run](https://github.com/Laragear/Compare/workflows/Tests/badge.svg)](https://github.com/Laragear/Compare/actions)[![Codecov coverage](https://camo.githubusercontent.com/d9671cdc8b095f75912f561695f51323cdf1ce2a356e9cbf485738f3c3fd17da/68747470733a2f2f636f6465636f762e696f2f67682f4c617261676561722f436f6d706172652f6272616e63682f312e782f67726170682f62616467652e7376673f746f6b656e3d7562766262436a754a65)](https://codecov.io/gh/Laragear/Compare)[![CodeClimate Maintainability](https://camo.githubusercontent.com/efded13e6b7a859cb0ba901e246f0be9f9f6770eb354a2a70f9dcfcc38c1d6a0/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f32356635373661653134303333306266383665642f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Laragear/Compare/maintainability)[![Sonarcloud Status](https://camo.githubusercontent.com/8286d675b0f7578c463d2919687aea20771fa1ac465dd0a56147e450a8a2a615/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d4c617261676561725f436f6d70617265266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=Laragear_Compare)[![Laravel Octane Compatibility](https://camo.githubusercontent.com/70359a356da237cd29561bc5d0bb80baae775b5ff62f288ed324755382858342/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2532304f6374616e652d436f6d70617469626c652d737563636573733f7374796c653d666c6174266c6f676f3d6c61726176656c)](https://laravel.com/docs/9.x/octane#introduction)

Small utility trait to fluently compare object values.

```
if ($comparable->is('wallet.available')->aboveZero()) {
    return 'You can buy with your wallet credits.';
}

return 'No credits? Buy some in the store!';
```

Become a sponsor
----------------

[](#become-a-sponsor)

[![](.github/assets/support.png)](https://github.com/sponsors/DarkGhostHunter)

Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can **[spread the word!](http://twitter.com/share?text=I%20am%20using%20this%20cool%20PHP%20package&url=https://github.com%2FLaragear%2FCompare&hashtags=PHP,Laravel)**

Requirements
------------

[](#requirements)

- Laravel 9.x or later
- PHP 8.0 or later

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

[](#installation)

Fire up Composer and require this package in your project.

```
composer require laragear/comparable

```

That's it.

Usage
-----

[](#usage)

Add the `Comparable` trait to your object, and that's it. You can start a comparison using `is()` with the key name, unless you want to compare the whole object.

```
use Laragear\Compare\Comparable;

class Wallet
{
    use Comparable;

    // ...
}
```

Once done, you can start a comparison using `is()`.

```
$wallet = new Wallet(['credits' => 1000]);

if ($wallet->is('credits')->aboveZero()) {
    return 'You have credits available, so go and spend some!';
}

return 'Your wallet is empty. Add some credits!';
```

> When not issuing a key, the whole object will be used to compare.

Behind the scenes, it uses `data_get()` from Laravel helpers to retrieve the values from your object using "dot" notation.

```
if ($wallet->is('pending.total')->aboveZero()) {
    return "You have {$wallet->pending->total} pending.";
}
```

To negate a condition, just issue `not()`, or the `not` property.

```
if ($wallet->is('pending.total')->not->belowZero()) {
    return 'If you dont have credits, we can lend you some.';
}
```

Available conditions
--------------------

[](#available-conditions)

[aboveZero](#abovezero)[equalOrGreaterThan](#equalorgreaterthan)[lessThan](#lessthan)[belowZero](#belowzero)[equalOrLessThan](#equalorlessthan)[null](#null)[between](#between)[exactly](#exactly)[true](#true)[blank](#blank)[false](#false)[truthy](#truthy)[containing](#containing)[falsy](#falsy)[zero](#zero)[containingOneItem](#containingoneitem)[filled](#filled)[counting](#counting)[greaterThan](#greaterthan)### `aboveZero()`

[](#abovezero)

Checks if a numeric value is above zero.

```
if ($wallet->is('amount')->aboveZero()) {
    return 'You still have credits left.';
}
```

### `belowZero()`

[](#belowzero)

Checks if a numeric value is below zero.

```
if ($wallet->is('amount')->belowZero()) {
    return 'The Wallet is empty.';
}
```

### `between()`

[](#between)

Check if the numeric value is between two numbers.

```
if ($product->is('weight')->between(10, 20)) {
    return 'This product can be picked up at the store.';
}
```

Issuing `false` as third parameter will make the comparison *exclusive*.

```
if ($product->is('weight')->between(10, 20, false)) {
    return 'The weight of the product is between 10.1 and 19.9 lbs.';
}
```

### `blank()`

[](#blank)

Check if the value is ["blank"](https://laravel.com/docs/9.x/helpers#method-blank).

```
if ($wallet->is('name')->blank()) {
    return 'Default Wallet';
}
```

### `counting()`

[](#counting)

Checks if a list contains the exact number of items.

```
if ($cart->is('items')->counting(10)) {
    return 'You are elegible for a discount for exactly 10 items.';
}
```

### `containing()`

[](#containing)

Checks if a string contains a string, or a list contains an item.

```
if ($product->is('name')->containing('discounted')) {
    return 'Discount are not applied to already discounted items.';
}
```

### `containingOneItem()`

[](#containingoneitem)

Check if the value is a list and contains only one item.

```
if ($cart->is('items')->containingOneItem()) {
    returns 'For free delivery, you need to add more than one item.';
}
```

### `equalOrGreaterThan()`

[](#equalorgreaterthan)

Check that a numeric value, or the value list count, is equal or greater than a number.

```
if ($cart->is('items')->equalOrGreaterThan(10)) {
    return 'For more than 10 items, you will need to pick up them in the store.'
}

if ($cart->is('total')->equalOrGreaterThan(1000)) {
    return 'Your cart qualifies for free delivery';
}
```

### `exactly()`

[](#exactly)

Check that a value is exactly the value given, strictly.

```
if ($product->is('name')->exactly('shoes')) {
    return 'Welp, these are shoes.';
}
```

### `false()`

[](#false)

Check if a value is exactly `false`.

```
if ($product->is('can_deliver')->false()) {
    return 'The product cannot be delivered.';
}
```

### `falsy()`

[](#falsy)

Check if a value *evaluates* to `false`.

```
if ($product->is('address')->false()) {
    return 'The product cannot be delivered without an address.';
}
```

### `equalOrLessThan()`

[](#equalorlessthan)

Check that a numeric value, or the value list count, is equal or less than a number.

```
if ($cart->is('items')->equalOrLessThan(1)) {
    return 'Add more items to qualify for delivery.'
}

if ($cart->is('total')->equalOrLessThan(1000)) {
    return 'Your cart does not qualify for free delivery';
}
```

### `filled()`

[](#filled)

Check if the value is ["filled"](https://laravel.com/docs/9.x/helpers#method-filled).

```
if ($wallet->is('name')->blank()) {
    return 'Default Wallet';
}
```

### `greaterThan()`

[](#greaterthan)

Check if the numeric value, or the list items count, is greater than the issued number,

```
if ($product->is('weight')->greaterThan(100)) {
    return 'This product is too heavy to be sent. You have to pick it up.';
}
```

### `lessThan()`

[](#lessthan)

Check if the numeric value, or the list items count, is less than the issued number,

```
if ($product->is('weight')->greaterThan(100)) {
    return 'This product is too heavy to be sent. You have to pick it up.';
}

if ($cary->is('items')->greaterThan(10)) {
    return 'We wil divide your order on multiple deliveries of 10 items';
}
```

### `null()`

[](#null)

Check if the value is null.

```
if ($cart->is('promo_code')->null()) {
    return 'You can add a promo code to your code.';
}
```

### `true()`

[](#true)

Check if a value is exactly `true`.

```
if ($product->is('can_deliver')->true()) {
    return 'The product can be delivered.';
}
```

### `truthy()`

[](#truthy)

Check if a value *evaluates* to `true`.

```
if ($product->is('address')->true()) {
    return 'The products will be delivered to the issued address.';
}
```

### `zero()`

[](#zero)

Check if the numeric value, or the list items count, is exactly zero.

```
if ($cart->is('delivery_total')->zero()) {
    return 'This order has no cost of delivery. Enjoy!';
}

if ($cart->is('items')->zero()) {
    return 'Your cart is empty.';
}
```

Higher Order Comparisons
------------------------

[](#higher-order-comparisons)

You can access to a comparison result using dynamic properties:

`$object->blank``$object->false``$object->aboveZero``$object->filled``$object->falsy``$object->belowZero``$object->true``$object->null``$object->containingOneItem``$object->truthy``$object->zero`Laravel Octane compatibility
----------------------------

[](#laravel-octane-compatibility)

- There are no singletons using a stale application instance.
- There are no singletons using a stale config instance.
- There are no singletons using a stale request instance.
- There are no static properties written.

There should be no problems using this package with Laravel Octane.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
=======

[](#license)

This specific package version is licensed under the terms of the [MIT License](LICENSE.md), at time of publishing.

[Laravel](https://laravel.com) is a Trademark of [Taylor Otwell](https://github.com/TaylorOtwell/). Copyright © 2011-2022 Laravel LLC.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 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 ~469 days

Total

3

Last Release

520d ago

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

v1.1.0PHP 8.\*

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5141911?v=4)[Italo](/maintainers/DarkGhostHunter)[@DarkGhostHunter](https://github.com/DarkGhostHunter)

---

Top Contributors

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

---

Tags

laravelcomparing

### Embed Badge

![Health badge](/badges/laragear-compare/health.svg)

```
[![Health](https://phpackages.com/badges/laragear-compare/health.svg)](https://phpackages.com/packages/laragear-compare)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M11](/packages/renatomarinho-laravel-page-speed)[vinkius-labs/laravel-page-speed

Laravel Page Speed

2.5k12.5k1](/packages/vinkius-labs-laravel-page-speed)[emargareten/inertia-modal

Inertia Modal is a Laravel package that lets you implement backend-driven modal dialogs for Inertia apps.

90142.9k](/packages/emargareten-inertia-modal)[wearepixel/laravel-cart

A cart implementation for Laravel

1374.8k](/packages/wearepixel-laravel-cart)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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