1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Recca0120\Repository\Concerns; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Recca0120\Repository\Method; |
7
|
|
|
|
8
|
|
|
trait EloquentBuildsQueries |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Add a where clause on the primary key to the query. |
12
|
|
|
* |
13
|
|
|
* @param mixed $id |
14
|
|
|
* @return $this |
15
|
|
|
*/ |
16
|
1 |
|
public function whereKey($id) |
17
|
|
|
{ |
18
|
1 |
|
$this->methods[] = new Method(__FUNCTION__, [$id]); |
|
|
|
|
19
|
|
|
|
20
|
1 |
|
return $this; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Add a where clause on the primary key to the query. |
25
|
|
|
* |
26
|
|
|
* @param mixed $id |
27
|
|
|
* @return $this |
28
|
|
|
*/ |
29
|
1 |
|
public function whereKeyNot($id) |
30
|
|
|
{ |
31
|
1 |
|
$this->methods[] = new Method(__FUNCTION__, [$id]); |
32
|
|
|
|
33
|
1 |
|
return $this; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Set the relationships that should be eager loaded. |
38
|
|
|
* |
39
|
|
|
* @param mixed $relations |
40
|
|
|
* @return $this |
41
|
|
|
*/ |
42
|
1 |
|
public function with($relations) |
|
|
|
|
43
|
|
|
{ |
44
|
1 |
|
$this->methods[] = new Method(__FUNCTION__, func_get_args()); |
45
|
|
|
|
46
|
1 |
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Prevent the specified relations from being eager loaded. |
51
|
|
|
* |
52
|
|
|
* @param mixed $relations |
53
|
|
|
* @return $this |
54
|
|
|
*/ |
55
|
1 |
|
public function without($relations) |
|
|
|
|
56
|
|
|
{ |
57
|
1 |
|
$this->methods[] = new Method(__FUNCTION__, func_get_args()); |
58
|
|
|
|
59
|
1 |
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Set the underlying query builder instance. |
64
|
|
|
* |
65
|
|
|
* @param \Illuminate\Database\Query\Builder $query |
66
|
|
|
* @return $this |
67
|
|
|
*/ |
68
|
1 |
|
public function setQuery($query) |
69
|
|
|
{ |
70
|
1 |
|
$this->methods[] = new Method(__FUNCTION__, [$query]); |
71
|
|
|
|
72
|
1 |
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Set a model instance for the model being queried. |
77
|
|
|
* |
78
|
|
|
* @param \Illuminate\Database\Eloquent\Model $model |
79
|
|
|
* @return $this |
80
|
|
|
*/ |
81
|
1 |
|
public function setModel(Model $model) |
82
|
|
|
{ |
83
|
1 |
|
$this->methods[] = new Method(__FUNCTION__, [$model]); |
84
|
|
|
|
85
|
1 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Begin querying the model on the write connection. |
90
|
|
|
* |
91
|
|
|
* @return \Illuminate\Database\Query\Builder |
92
|
|
|
*/ |
93
|
1 |
|
public function onWriteConnection() |
94
|
|
|
{ |
95
|
1 |
|
return $this->useWritePdo(); |
|
|
|
|
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: