1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelFreelancerNL\Aranguent\Eloquent\Concerns; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Builder; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo as IlluminateBelongsTo; |
8
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany as IlluminateBelongsToMany; |
9
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany as IlluminateHasMany; |
10
|
|
|
use Illuminate\Database\Eloquent\Relations\HasOne as IlluminateHasOne; |
11
|
|
|
use Illuminate\Database\Eloquent\Relations\HasOneThrough as IlluminateHasOneThrough; |
12
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany as IlluminateMorphMany; |
13
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphOne as IlluminateMorphOne; |
14
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo as IlluminateMorphTo; |
15
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphToMany as IlluminateMorphToMany; |
16
|
|
|
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\BelongsTo; |
17
|
|
|
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\BelongsToMany; |
18
|
|
|
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\HasMany; |
19
|
|
|
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\HasOne; |
20
|
|
|
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\HasOneThrough; |
21
|
|
|
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\MorphMany; |
22
|
|
|
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\MorphOne; |
23
|
|
|
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\MorphTo; |
24
|
|
|
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\MorphToMany; |
25
|
|
|
|
26
|
|
|
trait HasAranguentRelationships |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Instantiate a new BelongsTo relationship. |
30
|
|
|
* |
31
|
|
|
* @param Builder $query |
32
|
|
|
* @param Model $child |
33
|
|
|
* @param string $foreignKey |
34
|
|
|
* @param string $ownerKey |
35
|
|
|
* @param string $relation |
36
|
|
|
* @return IlluminateBelongsTo |
37
|
|
|
*/ |
38
|
14 |
|
protected function newBelongsTo(Builder $query, Model $child, $foreignKey, $ownerKey, $relation) |
39
|
|
|
{ |
40
|
14 |
|
return new BelongsTo($query, $child, $foreignKey, $ownerKey, $relation); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Instantiate a new BelongsToMany relationship. |
45
|
|
|
* |
46
|
|
|
* @param Builder $query |
47
|
|
|
* @param Model $parent |
48
|
|
|
* @param string $table |
49
|
|
|
* @param string $foreignPivotKey |
50
|
|
|
* @param string $relatedPivotKey |
51
|
|
|
* @param string $parentKey |
52
|
|
|
* @param string $relatedKey |
53
|
|
|
* @param string|null $relationName |
54
|
|
|
* @return IlluminateBelongsToMany |
55
|
|
|
*/ |
56
|
6 |
|
protected function newBelongsToMany( |
57
|
|
|
Builder $query, |
58
|
|
|
Model $parent, |
59
|
|
|
$table, |
60
|
|
|
$foreignPivotKey, |
61
|
|
|
$relatedPivotKey, |
62
|
|
|
$parentKey, |
63
|
|
|
$relatedKey, |
64
|
|
|
$relationName = null |
65
|
|
|
) { |
66
|
6 |
|
return new BelongsToMany( |
67
|
6 |
|
$query, |
68
|
|
|
$parent, |
69
|
|
|
$table, |
70
|
|
|
$foreignPivotKey, |
71
|
|
|
$relatedPivotKey, |
72
|
|
|
$parentKey, |
73
|
|
|
$relatedKey, |
74
|
|
|
$relationName |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Instantiate a new HasMany relationship. |
80
|
|
|
* |
81
|
|
|
* @param Builder $query |
82
|
|
|
* @param Model $parent |
83
|
|
|
* @param string $foreignKey |
84
|
|
|
* @param string $localKey |
85
|
|
|
* @return IlluminateHasMany |
86
|
|
|
*/ |
87
|
4 |
|
protected function newHasMany(Builder $query, Model $parent, $foreignKey, $localKey) |
88
|
|
|
{ |
89
|
4 |
|
return new HasMany($query, $parent, $foreignKey, $localKey); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Instantiate a new HasOne relationship. |
94
|
|
|
* |
95
|
|
|
* @param Builder $query |
96
|
|
|
* @param Model $parent |
97
|
|
|
* @param string $foreignKey |
98
|
|
|
* @param string $localKey |
99
|
|
|
* @return IlluminateHasOne |
100
|
|
|
*/ |
101
|
9 |
|
protected function newHasOne(Builder $query, Model $parent, $foreignKey, $localKey) |
102
|
|
|
{ |
103
|
9 |
|
return new HasOne($query, $parent, $foreignKey, $localKey); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Instantiate a new HasOneThrough relationship. |
108
|
|
|
* |
109
|
|
|
* @param Builder $query |
110
|
|
|
* @param Model $farParent |
111
|
|
|
* @param Model $throughParent |
112
|
|
|
* @param string $firstKey |
113
|
|
|
* @param string $secondKey |
114
|
|
|
* @param string $localKey |
115
|
|
|
* @param string $secondLocalKey |
116
|
|
|
* @return IlluminateHasOneThrough |
117
|
|
|
*/ |
118
|
|
|
protected function newHasOneThrough( |
119
|
|
|
Builder $query, |
120
|
|
|
Model $farParent, |
121
|
|
|
Model $throughParent, |
122
|
|
|
$firstKey, |
123
|
|
|
$secondKey, |
124
|
|
|
$localKey, |
125
|
|
|
$secondLocalKey |
126
|
|
|
) { |
127
|
|
|
return new HasOneThrough($query, $farParent, $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Instantiate a new MorphMany relationship. |
132
|
|
|
* |
133
|
|
|
* @param Builder $query |
134
|
|
|
* @param Model $parent |
135
|
|
|
* @param string $type |
136
|
|
|
* @param string $id |
137
|
|
|
* @param string $localKey |
138
|
|
|
* @return IlluminateMorphMany |
139
|
|
|
*/ |
140
|
3 |
|
protected function newMorphMany(Builder $query, Model $parent, $type, $id, $localKey) |
141
|
|
|
{ |
142
|
3 |
|
return new MorphMany($query, $parent, $type, $id, $localKey); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Instantiate a new MorphOne relationship. |
147
|
|
|
* |
148
|
|
|
* @param Builder $query |
149
|
|
|
* @param Model $parent |
150
|
|
|
* @param string $type |
151
|
|
|
* @param string $id |
152
|
|
|
* @param string $localKey |
153
|
|
|
* @return IlluminateMorphOne |
154
|
|
|
*/ |
155
|
3 |
|
protected function newMorphOne(Builder $query, Model $parent, $type, $id, $localKey) |
156
|
|
|
{ |
157
|
3 |
|
return new MorphOne($query, $parent, $type, $id, $localKey); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Instantiate a new MorphTo relationship. |
162
|
|
|
* |
163
|
|
|
* @param Builder $query |
164
|
|
|
* @param Model $parent |
165
|
|
|
* @param string $foreignKey |
166
|
|
|
* @param string $ownerKey |
167
|
|
|
* @param string $type |
168
|
|
|
* @param string $relation |
169
|
|
|
* @return IlluminateMorphTo |
170
|
|
|
*/ |
171
|
4 |
|
protected function newMorphTo(Builder $query, Model $parent, $foreignKey, $ownerKey, $type, $relation) |
172
|
|
|
{ |
173
|
4 |
|
return new MorphTo($query, $parent, $foreignKey, $ownerKey, $type, $relation); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Instantiate a new MorphToMany relationship. |
178
|
|
|
* |
179
|
|
|
* Laravel API PHPMD exclusions |
180
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
181
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList) |
182
|
|
|
* |
183
|
|
|
* @param Builder $query |
184
|
|
|
* @param Model $parent |
185
|
|
|
* @param string $name |
186
|
|
|
* @param string $table |
187
|
|
|
* @param string $foreignPivotKey |
188
|
|
|
* @param string $relatedPivotKey |
189
|
|
|
* @param string $parentKey |
190
|
|
|
* @param string $relatedKey |
191
|
|
|
* @param string|null $relationName |
192
|
|
|
* @param bool $inverse |
193
|
|
|
* @return IlluminateMorphToMany |
194
|
|
|
*/ |
195
|
6 |
|
protected function newMorphToMany( |
196
|
|
|
Builder $query, |
197
|
|
|
Model $parent, |
198
|
|
|
$name, |
199
|
|
|
$table, |
200
|
|
|
$foreignPivotKey, |
201
|
|
|
$relatedPivotKey, |
202
|
|
|
$parentKey, |
203
|
|
|
$relatedKey, |
204
|
|
|
$relationName = null, |
205
|
|
|
$inverse = false |
206
|
|
|
) { |
207
|
6 |
|
return new MorphToMany( |
208
|
6 |
|
$query, |
209
|
|
|
$parent, |
210
|
|
|
$name, |
211
|
|
|
$table, |
212
|
|
|
$foreignPivotKey, |
213
|
|
|
$relatedPivotKey, |
214
|
|
|
$parentKey, |
215
|
|
|
$relatedKey, |
216
|
|
|
$relationName, |
217
|
|
|
$inverse |
218
|
|
|
); |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|