Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Dec 21, 2021
1 parent 1bea7e2 commit 0e4fad5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Support/Includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public function parse(Request $request, string $prefix): Collection

abort_if(is_array($includes), 400, 'The include parameter must be a comma seperated list of relationship paths.');

return Collection::make(explode(',', $includes))
/** @var Collection */
$includes = Collection::make(explode(',', $includes))
->when($prefix !== '', function (Collection $includes) use ($prefix): Collection {
return $includes->filter(fn (string $include): bool => Str::startsWith($include, $prefix));
})
->map(fn ($include): string => Str::before(Str::after($include, $prefix), '.'))
});

return $includes->map(fn ($include): string => Str::before(Str::after($include, $prefix), '.'))
->uniqueStrict()
->filter(fn (string $include): bool => $include !== '');
});
Expand Down

0 comments on commit 0e4fad5

Please sign in to comment.