Skip to content

Commit 3e25b76

Browse files
author
Admin
committed
1 parent 3f6ac41 commit 3e25b76

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Eloquent/CustomRelations/Builders/CleverEloquentBuilder.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,31 @@ protected function getBelongsToRelation(MorphTo $relation, $type): BelongsTo
6969

7070
return $belongsTo;
7171
}
72+
73+
/**
74+
* If $relations is list array and $callback is Closure, the closure will be applied to all relations from the list
75+
* @inheritDoc
76+
*/
77+
public function with($relations, $callback = null): static
78+
{
79+
if (!$callback instanceof \Closure) {
80+
$this->eagerLoad = \array_merge(
81+
$this->eagerLoad,
82+
$this->parseWithRelations(\is_string($relations) ? \func_get_args() : $relations)
83+
);
84+
85+
return $this;
86+
}
87+
88+
$this->eagerLoad = \array_merge($this->eagerLoad, $this->parseWithRelations(
89+
(\is_array($relations) && \array_values($relations) === $relations) ?
90+
\array_map(
91+
fn (string $relation): \Closure => $callback,
92+
\array_flip($relations)
93+
) :
94+
[$relations => $callback]
95+
));
96+
97+
return $this;
98+
}
7299
}

0 commit comments

Comments
 (0)