PHP code example of laragear / compare

1. Go to this page and download the library: Download laragear/compare library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laragear / compare example snippets


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

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

use Laragear\Compare\Comparable;

class Wallet
{
    use Comparable;
    
    // ...
}

$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!';

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

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

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

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

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

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

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

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

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

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

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';
}

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

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

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

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';
}


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

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

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';
}

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

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

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

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.';
}