-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathNotEquals.php
44 lines (36 loc) · 1.16 KB
/
NotEquals.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
declare(strict_types=1);
namespace Asseco\JsonQueryBuilder\SearchCallbacks;
use Asseco\JsonQueryBuilder\CategorizedValues;
use Exception;
use Illuminate\Database\Eloquent\Builder;
class NotEquals extends AbstractCallback
{
public static function operator(): string
{
return '!=';
}
/**
* @param Builder $builder
* @param string $column
* @param CategorizedValues $values
* @return void
*
* @throws Exception
*/
public function execute(Builder $builder, string $column, CategorizedValues $values): void
{
foreach (array_merge($values->andLike, $values->notLike) as $like) {
if ($this->isDate($this->searchParser->type)) {
throw new Exception('Not operator is not supported for date(time) fields');
}
$builder->where($column, 'NOT ' . $this->getLikeOperator(), $like);
}
if ($values->null || $values->notNull) {
$builder->whereNotNull($column);
}
if (array_merge($values->and, $values->not)) {
$builder->whereNotIn($column, array_merge($values->and, $values->not));
}
}
}