Skip to content

Commit b43a466

Browse files
author
Marius
committed
fix eager loading retroactively laravel/framework#51825
1 parent aae9bfc commit b43a466

File tree

1 file changed

+74
-35
lines changed

1 file changed

+74
-35
lines changed

src/Eloquent/CustomRelations/HasCleverRelationships.php

Lines changed: 74 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Eloquent\Builder;
66
use Illuminate\Database\Eloquent\Concerns\HasRelationships;
7+
use Illuminate\Database\Eloquent\Model;
78
use Illuminate\Database\Eloquent\Relations\BelongsTo;
89
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
910
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -14,7 +15,6 @@
1415
use Illuminate\Database\Eloquent\Relations\MorphOne;
1516
use Illuminate\Database\Eloquent\Relations\MorphTo;
1617
use Illuminate\Database\Eloquent\Relations\MorphToMany;
17-
use MacropaySolutions\LaravelCrudWizard\Models\BaseModel as Model;
1818

1919
/**
2020
* @see HasRelationships
@@ -24,7 +24,10 @@ trait HasCleverRelationships
2424
{
2525
public ?string $nowEagerLoadingRelationNameWithNoConstraints = null;
2626

27-
protected function newHasOne(Builder $query, Model $parent, string $foreignKey, string $localKey): HasOne
27+
/**
28+
* @inheritDoc
29+
*/
30+
protected function newHasOne(Builder $query, Model $parent, $foreignKey, $localKey): HasOne
2831
{
2932
return new class($query, $parent, $foreignKey, $localKey) extends HasOne {
3033
use RelationCleverTrait;
@@ -38,14 +41,17 @@ public function __construct(Builder $query, Model $parent, string $foreignKey, s
3841
};
3942
}
4043

44+
/**
45+
* @inheritDoc
46+
*/
4147
protected function newHasOneThrough(
4248
Builder $query,
4349
Model $farParent,
4450
Model $throughParent,
45-
string $firstKey,
46-
string $secondKey,
47-
string $localKey,
48-
string $secondLocalKey
51+
$firstKey,
52+
$secondKey,
53+
$localKey,
54+
$secondLocalKey
4955
): HasOneThrough {
5056
return new class(
5157
$query,
@@ -82,7 +88,10 @@ public function __construct(
8288
};
8389
}
8490

85-
protected function newMorphOne(Builder $query, Model $parent, string $type, string $id, string $localKey): MorphOne
91+
/**
92+
* @inheritDoc
93+
*/
94+
protected function newMorphOne(Builder $query, Model $parent, $type, $id, $localKey): MorphOne
8695
{
8796
return new class($query, $parent, $type, $id, $localKey) extends MorphOne {
8897
use RelationCleverTrait;
@@ -96,12 +105,15 @@ public function __construct(Builder $query, Model $parent, string $type, string
96105
};
97106
}
98107

108+
/**
109+
* @inheritDoc
110+
*/
99111
protected function newBelongsTo(
100112
Builder $query,
101113
Model $child,
102-
string $foreignKey,
103-
string $ownerKey,
104-
string $relation
114+
$foreignKey,
115+
$ownerKey,
116+
$relation
105117
): BelongsTo {
106118
return new class($query, $child, $foreignKey, $ownerKey, $relation) extends BelongsTo {
107119
use RelationCleverTrait;
@@ -120,13 +132,16 @@ public function __construct(
120132
};
121133
}
122134

135+
/**
136+
* @inheritDoc
137+
*/
123138
protected function newMorphTo(
124139
Builder $query,
125140
Model $parent,
126-
string $foreignKey,
127-
string $ownerKey,
128-
string $type,
129-
string $relation
141+
$foreignKey,
142+
$ownerKey,
143+
$type,
144+
$relation
130145
): MorphTo {
131146
return new class($query, $parent, $foreignKey, $ownerKey, $type, $relation) extends MorphTo {
132147
use RelationCleverTrait;
@@ -146,7 +161,10 @@ public function __construct(
146161
};
147162
}
148163

149-
protected function newHasMany(Builder $query, Model $parent, string $foreignKey, string $localKey): HasMany
164+
/**
165+
* @inheritDoc
166+
*/
167+
protected function newHasMany(Builder $query, Model $parent, $foreignKey, $localKey): HasMany
150168
{
151169
return new class($query, $parent, $foreignKey, $localKey) extends HasMany {
152170
use RelationCleverTrait;
@@ -160,14 +178,17 @@ public function __construct(Builder $query, Model $parent, string $foreignKey, s
160178
};
161179
}
162180

181+
/**
182+
* @inheritDoc
183+
*/
163184
protected function newHasManyThrough(
164185
Builder $query,
165186
Model $farParent,
166187
Model $throughParent,
167-
string $firstKey,
168-
string $secondKey,
169-
string $localKey,
170-
string $secondLocalKey
188+
$firstKey,
189+
$secondKey,
190+
$localKey,
191+
$secondLocalKey
171192
): HasManyThrough {
172193
return new class($query, $farParent, $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey) extends
173194
HasManyThrough {
@@ -197,6 +218,9 @@ public function __construct(
197218
};
198219
}
199220

221+
/**
222+
* @inheritDoc
223+
*/
200224
protected function newMorphMany(Builder $query, Model $parent, $type, $id, $localKey): MorphMany
201225
{
202226
return new class($query, $parent, $type, $id, $localKey) extends MorphMany {
@@ -211,15 +235,18 @@ public function __construct(Builder $query, Model $parent, string $type, string
211235
};
212236
}
213237

238+
/**
239+
* @inheritDoc
240+
*/
214241
protected function newBelongsToMany(
215242
Builder $query,
216243
Model $parent,
217-
string $table,
218-
string $foreignPivotKey,
219-
string $relatedPivotKey,
220-
string $parentKey,
221-
string $relatedKey,
222-
?string $relationName = null
244+
$table,
245+
$foreignPivotKey,
246+
$relatedPivotKey,
247+
$parentKey,
248+
$relatedKey,
249+
$relationName = null
223250
): BelongsToMany {
224251
return new class($query, $parent, $table, $foreignPivotKey, $relatedPivotKey, $parentKey, $relatedKey, $relationName) extends
225252
BelongsToMany {
@@ -251,20 +278,32 @@ public function __construct(
251278
};
252279
}
253280

281+
/**
282+
* @inheritDoc
283+
*/
254284
protected function newMorphToMany(
255285
Builder $query,
256286
Model $parent,
257-
string $name,
258-
string $table,
259-
string $foreignPivotKey,
260-
string $relatedPivotKey,
261-
string $parentKey,
262-
string $relatedKey,
263-
?string $relationName = null,
264-
bool $inverse = false
287+
$name,
288+
$table,
289+
$foreignPivotKey,
290+
$relatedPivotKey,
291+
$parentKey,
292+
$relatedKey,
293+
$relationName = null,
294+
$inverse = false
265295
): MorphToMany {
266-
return new class($query, $parent, $name, $table, $foreignPivotKey, $relatedPivotKey, $parentKey, $relatedKey,
267-
$relationName, $inverse
296+
return new class(
297+
$query,
298+
$parent,
299+
$name,
300+
$table,
301+
$foreignPivotKey,
302+
$relatedPivotKey,
303+
$parentKey,
304+
$relatedKey,
305+
$relationName,
306+
$inverse
268307
) extends MorphToMany {
269308
use RelationCleverTrait;
270309

0 commit comments

Comments
 (0)