Skip to content

Is Between Or Not

Gilberto Junior edited this page Nov 29, 2019 · 5 revisions

Operators

Is Between

A operator that represents a range of results.

Syntax

public function isBetween(string $column, string|int|float $value1, string|int|float $value2): self;
public function isBetween(string $column, array $values): self;

Alias

public function between(string $column, string|int|float $value1, string|int|float $value2): self;
public function between(string $column, string $column, array $values): self;

Example 1

PHP's way:

$repository->isBetween('price', 1.99, 9.99);

SQL's Representation:

WHERE price BETWEEN 1.99 AND 9.99;

Example 2

PHP's way:

$repository->isBetween('created_at', ['2019-10-02 00:00:00', '2019-10-12 23:59:59']);

SQL's Representation:

WHERE created_at BETWEEN '2019-10-02 00:00:00' AND '2019-10-12 23:59:59';

Example 3

PHP's way:

$repository->between('age', 18, 21)
    ->orBetween('height', [5.0, 5.11]);

SQL's Representation:

WHERE age BETWEEN 18 AND 21 OR height BETWEEM 5.0 AND 5.11;

Is Not Between

A operator that excludes a range of results.

Syntax

public function isNotBetween(string $column, string|int|float $value1, string|int|float $value2): self;
public function isNotBetween(string $column, array $values): self;

Alias

public function notBetween(string $column, string|int|float $value1, string|int|float $value2): self;
public function notBetween(string $column, array $values): self;

Example 1

PHP's way:

$repository->isNotBetween('category_id', 456, 999);

SQL's Representation:

WHERE category_id NOT BETWEEN 456 AND 999;

Example 2

PHP's way:

$repository->notBetween('user_id', [100, 200]);

SQL's Representation:

WHERE user_id NOT BETWEEN 100 AND 200;

Example 3

PHP's way:

$repository->isNotBetween('size', 1000, 2000)
    ->orIsNotBetween('weight', 11, 22);

SQL's Representation:

WHERE size NOT BETWEEN 1000 AND 2000 AND weight NOT BETWEEN 11 AND 22

Example 4

PHP's way:

$repository->notBetween('CAST(created_at AS DATE)', ['2010-01-01', '2010-12-31'])
    ->orNotBetween('price', 18.20, 23.45);

SQL's Representation:

WHERE CAST(created_at AS DATE) NOT BETWEEN '2010-01-01' AND '2010-12-31' 
OR price NOT BETWEEN 18.20 AND 23.45;

🡄 Is Equal To Or Not | Like Or Not 🡆

Clone this wiki locally