1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Modules\Core\Traits\Criteria; |
5
|
|
|
|
6
|
|
|
trait ParseSearchWhereTrait |
7
|
|
|
{ |
8
|
|
|
/** @var \Illuminate\Http\Request $request */ |
9
|
|
|
protected $request; |
10
|
|
|
/** @var \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder $model */ |
11
|
|
|
protected $model; |
12
|
|
|
/** @var \Prettus\Repository\Contracts\RepositoryInterface $repository */ |
13
|
|
|
protected $repository; |
14
|
|
|
protected $search; |
15
|
|
|
protected $searchData; |
16
|
|
|
protected $searchFields; |
17
|
|
|
protected $isFirstField; |
18
|
|
|
protected $modelForceAndWhere; |
19
|
|
|
protected $fieldsSearchable; |
20
|
|
|
protected $fields; |
21
|
|
|
protected $filter; |
22
|
|
|
protected $orderBy; |
23
|
|
|
protected $sortedBy; |
24
|
|
|
protected $with; |
25
|
|
|
protected $searchJoin; |
26
|
|
|
protected $acceptedConditions; |
27
|
|
|
protected $originalFields; |
28
|
|
|
|
29
|
|
|
use ParseSearchAndClosureTrait; |
30
|
|
|
use ParseSearchAndRelationClosureTrait; |
31
|
|
|
use ParseSearchOrClosureTrait; |
32
|
|
|
use ParseSearchOrRelationClosureTrait; |
33
|
|
|
|
34
|
|
|
protected function parseSearchWhere($value, $relation, $field, $condition) |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
if ($this->isFirstField || $this->modelForceAndWhere) { |
38
|
|
|
$this->parseSearchAndWhere($value, $relation, $field, $condition); |
39
|
|
|
} else { |
40
|
|
|
$this->parseSearchOrWhere($value, $relation, $field, $condition); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function parseSearchOrWhere($value, $relation, $field, $condition) |
45
|
|
|
{ |
46
|
|
|
if (!is_null($value)) { |
47
|
|
|
if (!is_null($relation)) { |
48
|
|
|
$this->parseSearchOrRelationClosure($value, $relation, $field, $condition); |
49
|
|
|
} else { |
50
|
|
|
$this->parseSearchOrClosure($value, $field, $condition); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function parseSearchAndWhere($value, $relation, $field, $condition) |
56
|
|
|
{ |
57
|
|
|
if (!is_null($value)) { |
58
|
|
|
if (!is_null($relation)) { |
59
|
|
|
$this->parseSearchAndRelationClosure($value, $relation, $field, $condition); |
60
|
|
|
} else { |
61
|
|
|
$this->parseSearchAndClosure($value, $field, $condition); |
62
|
|
|
} |
63
|
|
|
$this->isFirstField = false; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |