-
Notifications
You must be signed in to change notification settings - Fork 3
/
Untitled-1
45 lines (42 loc) · 1.56 KB
/
Untitled-1
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
45
this.addWheres = function ($query){
let filters = this.request.input('filters', '').split(",")
$relations.forEach((relation, index)=>{ $query.with(relation)})
filters.forEach(($value, $key)=>{
//If non equality operator
if ( Array.isArray($value)) {
$value.foreach($valueToOperate, $operator) {
switch ($operator) {
case 'lte':
$query = $query -> where($key, '<=', $valueToOperate);
break;
case 'lt':
$query = $query -> where($key, '<', $valueToOperate);
break;
case 'gte':
$query = $query -> where($key, '>=', $valueToOperate);
break;
case 'gt':
$query = $query -> where($key, '>', $valueToOperate);
break;
case 'startsWith':
$query = $query -> where($key, 'like', "{$valueToOperate}%");
break;
case 'endsWith':
$query = $query -> where($key, 'like', "%{$valueToOperate}");
break;
case 'between':
if (is_array($valueToOperate))
$query = $query -> whereBetween($key, $valueToOperate);
break;
case 'in':
if (is_array($valueToOperate))
$query = $query -> whereIn($key, $valueToOperate);
break;
}
}
} else {
$query = $query -> where($key, $value);
}
})
return $query
}