Download the PHP package laragear/compare without Composer
On this page you can find all versions of the php package laragear/compare. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package compare
Modern PHP has very flexible Comparison Operators, so this package is no longer needed.
Comparable
Small utility trait to fluently compare object values.
Become a sponsor
Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can spread the word!
Requirements
- Laravel 9.x or later
- PHP 8.0 or later
Installation
Fire up Composer and require this package in your project.
composer require laragear/comparable
That's it.
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.
Once done, you can start a comparison using is()
.
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.
To negate a condition, just issue not()
, or the not
property.
Available conditions
aboveZero | equalOrGreaterThan | lessThan |
belowZero | equalOrLessThan | null |
between | exactly | true |
blank | false | truthy |
containing | falsy | zero |
containingOneItem | filled | |
counting | greaterThan |
aboveZero()
Checks if a numeric value is above zero.
belowZero()
Checks if a numeric value is below zero.
between()
Check if the numeric value is between two numbers.
Issuing false
as third parameter will make the comparison exclusive.
blank()
Check if the value is "blank".
counting()
Checks if a list contains the exact number of items.
containing()
Checks if a string contains a string, or a list contains an item.
containingOneItem()
Check if the value is a list and contains only one item.
equalOrGreaterThan()
Check that a numeric value, or the value list count, is equal or greater than a number.
exactly()
Check that a value is exactly the value given, strictly.
false()
Check if a value is exactly false
.
falsy()
Check if a value evaluates to false
.
equalOrLessThan()
Check that a numeric value, or the value list count, is equal or less than a number.
filled()
Check if the value is "filled".
greaterThan()
Check if the numeric value, or the list items count, is greater than the issued number,
lessThan()
Check if the numeric value, or the list items count, is less than the issued number,
null()
Check if the value is null.
true()
Check if a value is exactly true
.
truthy()
Check if a value evaluates to true
.
zero()
Check if the numeric value, or the list items count, is exactly zero.
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
- 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
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
License
This specific package version is licensed under the terms of the MIT License, at time of publishing.
Laravel is a Trademark of Taylor Otwell. Copyright © 2011-2022 Laravel LLC.