-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDate.php
34 lines (28 loc) · 779 Bytes
/
Date.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
<?php
namespace FerFabricio\RestGetFilters\Filters;
use Illuminate\Database\Eloquent\Builder;
class Date extends AbstractFilter implements FilterInterface
{
public const IDENTIFIER = 'date';
/**
* @return array
*/
public function operators(): array
{
return [
'gt' => '>',
'gte' => '>=',
'lt' => '<',
'lte' => '<=',
];
}
public function apply(Builder $query, string $column, array $filter): Builder
{
$operator = $this->identifyOperator($column, $filter);
$key = $this->identifyKey($column, $filter);
if (array_key_exists($key, $filter)) {
$query->whereDate($column, $operator, $filter[$key]);
}
return $query;
}
}