15
15
use Illuminate \Database \Eloquent \Relations \MorphOne ;
16
16
use Illuminate \Database \Eloquent \Relations \MorphTo ;
17
17
use Illuminate \Database \Eloquent \Relations \MorphToMany ;
18
+ use MacropaySolutions \LaravelCrudWizard \Models \BaseModel ;
18
19
19
20
/**
20
21
* @see HasRelationships
@@ -29,12 +30,17 @@ trait HasCleverRelationships
29
30
*/
30
31
protected function newHasOne (Builder $ query , Model $ parent , $ foreignKey , $ localKey ): HasOne
31
32
{
32
- return new class ($ query , $ parent , $ foreignKey , $ localKey ) extends HasOne {
33
+ return new class ($ query , $ parent , $ foreignKey , $ localKey, $ this ) extends HasOne {
33
34
use RelationCleverTrait;
34
35
35
- public function __construct (Builder $ query , Model $ parent , string $ foreignKey , string $ localKey )
36
- {
37
- $ this ->setConstraintsStaticFlag ($ parent );
36
+ public function __construct (
37
+ Builder $ query ,
38
+ Model $ parent ,
39
+ string $ foreignKey ,
40
+ string $ localKey ,
41
+ BaseModel $ resourceModel
42
+ ) {
43
+ $ this ->setConstraintsStaticFlag ($ resourceModel );
38
44
39
45
return parent ::__construct ($ query , $ parent , $ foreignKey , $ localKey );
40
46
}
@@ -53,14 +59,15 @@ protected function newHasOneThrough(
53
59
$ localKey ,
54
60
$ secondLocalKey
55
61
): HasOneThrough {
56
- return new class (
62
+ return new class (
57
63
$ query ,
58
64
$ farParent ,
59
65
$ throughParent ,
60
66
$ firstKey ,
61
67
$ secondKey ,
62
68
$ localKey ,
63
- $ secondLocalKey
69
+ $ secondLocalKey ,
70
+ $ this
64
71
) extends HasOneThrough {
65
72
use RelationCleverTrait;
66
73
@@ -71,9 +78,10 @@ public function __construct(
71
78
string $ firstKey ,
72
79
string $ secondKey ,
73
80
string $ localKey ,
74
- string $ secondLocalKey
81
+ string $ secondLocalKey ,
82
+ BaseModel $ resourceModel
75
83
) {
76
- $ this ->setConstraintsStaticFlag ($ throughParent );
84
+ $ this ->setConstraintsStaticFlag ($ resourceModel );
77
85
78
86
return parent ::__construct (
79
87
$ query ,
@@ -93,12 +101,18 @@ public function __construct(
93
101
*/
94
102
protected function newMorphOne (Builder $ query , Model $ parent , $ type , $ id , $ localKey ): MorphOne
95
103
{
96
- return new class ($ query , $ parent , $ type , $ id , $ localKey ) extends MorphOne {
104
+ return new class ($ query , $ parent , $ type , $ id , $ localKey, $ this ) extends MorphOne {
97
105
use RelationCleverTrait;
98
106
99
- public function __construct (Builder $ query , Model $ parent , string $ type , string $ id , string $ localKey )
100
- {
101
- $ this ->setConstraintsStaticFlag ($ parent );
107
+ public function __construct (
108
+ Builder $ query ,
109
+ Model $ parent ,
110
+ string $ type ,
111
+ string $ id ,
112
+ string $ localKey ,
113
+ BaseModel $ resourceModel
114
+ ) {
115
+ $ this ->setConstraintsStaticFlag ($ resourceModel );
102
116
103
117
return parent ::__construct ($ query , $ parent , $ type , $ id , $ localKey );
104
118
}
@@ -115,17 +129,18 @@ protected function newBelongsTo(
115
129
$ ownerKey ,
116
130
$ relation
117
131
): BelongsTo {
118
- return new class ($ query , $ child , $ foreignKey , $ ownerKey , $ relation ) extends BelongsTo {
132
+ return new class ($ query , $ child , $ foreignKey , $ ownerKey , $ relation, $ this ) extends BelongsTo {
119
133
use RelationCleverTrait;
120
134
121
135
public function __construct (
122
136
Builder $ query ,
123
137
Model $ child ,
124
138
string $ foreignKey ,
125
139
string $ ownerKey ,
126
- string $ relation
140
+ string $ relation ,
141
+ BaseModel $ resourceModel
127
142
) {
128
- $ this ->setConstraintsStaticFlag ($ child );
143
+ $ this ->setConstraintsStaticFlag ($ resourceModel );
129
144
130
145
return parent ::__construct ($ query , $ child , $ foreignKey , $ ownerKey , $ relation );
131
146
}
@@ -143,7 +158,7 @@ protected function newMorphTo(
143
158
$ type ,
144
159
$ relation
145
160
): MorphTo {
146
- return new class ($ query , $ parent , $ foreignKey , $ ownerKey , $ type , $ relation ) extends MorphTo {
161
+ return new class ($ query , $ parent , $ foreignKey , $ ownerKey , $ type , $ relation, $ this ) extends MorphTo {
147
162
use RelationCleverTrait;
148
163
149
164
public function __construct (
@@ -152,9 +167,10 @@ public function __construct(
152
167
string $ foreignKey ,
153
168
string $ ownerKey ,
154
169
string $ type ,
155
- string $ relation
170
+ string $ relation ,
171
+ BaseModel $ resourceModel
156
172
) {
157
- $ this ->setConstraintsStaticFlag ($ parent );
173
+ $ this ->setConstraintsStaticFlag ($ resourceModel );
158
174
159
175
return parent ::__construct ($ query , $ parent , $ foreignKey , $ ownerKey , $ type , $ relation );
160
176
}
@@ -166,12 +182,17 @@ public function __construct(
166
182
*/
167
183
protected function newHasMany (Builder $ query , Model $ parent , $ foreignKey , $ localKey ): HasMany
168
184
{
169
- return new class ($ query , $ parent , $ foreignKey , $ localKey ) extends HasMany {
185
+ return new class ($ query , $ parent , $ foreignKey , $ localKey, $ this ) extends HasMany {
170
186
use RelationCleverTrait;
171
187
172
- public function __construct (Builder $ query , Model $ parent , string $ foreignKey , string $ localKey )
173
- {
174
- $ this ->setConstraintsStaticFlag ($ parent );
188
+ public function __construct (
189
+ Builder $ query ,
190
+ Model $ parent ,
191
+ string $ foreignKey ,
192
+ string $ localKey ,
193
+ BaseModel $ resourceModel
194
+ ) {
195
+ $ this ->setConstraintsStaticFlag ($ resourceModel );
175
196
176
197
return parent ::__construct ($ query , $ parent , $ foreignKey , $ localKey );
177
198
}
@@ -190,8 +211,16 @@ protected function newHasManyThrough(
190
211
$ localKey ,
191
212
$ secondLocalKey
192
213
): HasManyThrough {
193
- return new class ($ query , $ farParent , $ throughParent , $ firstKey , $ secondKey , $ localKey , $ secondLocalKey ) extends
194
- HasManyThrough {
214
+ return new class (
215
+ $ query ,
216
+ $ farParent ,
217
+ $ throughParent ,
218
+ $ firstKey ,
219
+ $ secondKey ,
220
+ $ localKey ,
221
+ $ secondLocalKey ,
222
+ $ this
223
+ ) extends HasManyThrough {
195
224
use RelationCleverTrait;
196
225
197
226
public function __construct (
@@ -201,9 +230,10 @@ public function __construct(
201
230
string $ firstKey ,
202
231
string $ secondKey ,
203
232
string $ localKey ,
204
- string $ secondLocalKey
233
+ string $ secondLocalKey ,
234
+ BaseModel $ resourceModel
205
235
) {
206
- $ this ->setConstraintsStaticFlag ($ throughParent );
236
+ $ this ->setConstraintsStaticFlag ($ resourceModel );
207
237
208
238
return parent ::__construct (
209
239
$ query ,
@@ -223,12 +253,18 @@ public function __construct(
223
253
*/
224
254
protected function newMorphMany (Builder $ query , Model $ parent , $ type , $ id , $ localKey ): MorphMany
225
255
{
226
- return new class ($ query , $ parent , $ type , $ id , $ localKey ) extends MorphMany {
256
+ return new class ($ query , $ parent , $ type , $ id , $ localKey, $ this ) extends MorphMany {
227
257
use RelationCleverTrait;
228
258
229
- public function __construct (Builder $ query , Model $ parent , string $ type , string $ id , string $ localKey )
230
- {
231
- $ this ->setConstraintsStaticFlag ($ parent );
259
+ public function __construct (
260
+ Builder $ query ,
261
+ Model $ parent ,
262
+ string $ type ,
263
+ string $ id ,
264
+ string $ localKey ,
265
+ BaseModel $ resourceModel
266
+ ) {
267
+ $ this ->setConstraintsStaticFlag ($ resourceModel );
232
268
233
269
return parent ::__construct ($ query , $ parent , $ type , $ id , $ localKey );
234
270
}
@@ -248,8 +284,17 @@ protected function newBelongsToMany(
248
284
$ relatedKey ,
249
285
$ relationName = null
250
286
): BelongsToMany {
251
- return new class ($ query , $ parent , $ table , $ foreignPivotKey , $ relatedPivotKey , $ parentKey , $ relatedKey , $ relationName ) extends
252
- BelongsToMany {
287
+ return new class (
288
+ $ query ,
289
+ $ parent ,
290
+ $ table ,
291
+ $ foreignPivotKey ,
292
+ $ relatedPivotKey ,
293
+ $ parentKey ,
294
+ $ relatedKey ,
295
+ $ this ,
296
+ $ relationName
297
+ ) extends BelongsToMany {
253
298
use RelationCleverTrait;
254
299
255
300
public function __construct (
@@ -260,9 +305,10 @@ public function __construct(
260
305
string $ relatedPivotKey ,
261
306
string $ parentKey ,
262
307
string $ relatedKey ,
308
+ BaseModel $ resourceModel ,
263
309
?string $ relationName = null
264
310
) {
265
- $ this ->setConstraintsStaticFlag ($ parent );
311
+ $ this ->setConstraintsStaticFlag ($ resourceModel );
266
312
267
313
return parent ::__construct (
268
314
$ query ,
@@ -293,7 +339,7 @@ protected function newMorphToMany(
293
339
$ relationName = null ,
294
340
$ inverse = false
295
341
): MorphToMany {
296
- return new class (
342
+ return new class (
297
343
$ query ,
298
344
$ parent ,
299
345
$ name ,
@@ -303,7 +349,8 @@ protected function newMorphToMany(
303
349
$ parentKey ,
304
350
$ relatedKey ,
305
351
$ relationName ,
306
- $ inverse
352
+ $ inverse ,
353
+ $ this
307
354
) extends MorphToMany {
308
355
use RelationCleverTrait;
309
356
@@ -317,9 +364,10 @@ public function __construct(
317
364
string $ parentKey ,
318
365
string $ relatedKey ,
319
366
?string $ relationName ,
320
- bool $ inverse
367
+ bool $ inverse ,
368
+ BaseModel $ resourceModel
321
369
) {
322
- $ this ->setConstraintsStaticFlag ($ parent );
370
+ $ this ->setConstraintsStaticFlag ($ resourceModel );
323
371
324
372
return parent ::__construct (
325
373
$ query ,
0 commit comments