Skip to content

Commit 6b34fcd

Browse files
committed
Allow to define before() and after() callbacks
1 parent a17683c commit 6b34fcd

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/ResourceRelations.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ final public function __construct(
3838
protected Request $request,
3939
) {}
4040

41+
protected function before(Builder $query): void {}
42+
4143
final public function handle(Builder $query, Closure $next): Builder | Collection | LengthAwarePaginator {
44+
$this->before($query);
45+
4246
// check if query param wasn't defined and just return
4347
if (null !== $with = $this->request->query('with')) {
4448
// convert to array if it is a coma separated string
@@ -86,9 +90,13 @@ final public function handle(Builder $query, Closure $next): Builder | Collectio
8690
// append relation counts to the query
8791
$query->withCount($this->with_count);
8892

93+
$this->after($query);
94+
8995
return $next($query);
9096
}
9197

98+
protected function after(Builder $query): void {}
99+
92100
private function parseWiths(): void {
93101
$with = [];
94102
foreach ($this->with as $idx => $relation) {

0 commit comments

Comments
 (0)