$includeList) { if ($includeList !== null && ! Arr::accessible($includeList)) { $criteria[] = static::parseResourceCriteria($type, $includeList); } } } } return $criteria; } /** * Parse criteria instance from query string. */ protected static function parseCriteria(string $includeParam): Criteria { $paths = Str::of($includeParam)->explode(','); $paths = self::createIntermediatePaths($paths); return new Criteria($paths); } /** * Parse resource criteria instance from query string. */ protected static function parseResourceCriteria(string $type, string $includeParam): ResourceCriteria { $paths = Str::of($includeParam)->explode(','); $paths = self::createIntermediatePaths($paths); return new ResourceCriteria(Str::lower($type), $paths); } /** * Create the intermediate paths as if they were in the URL. * * @param Collection $paths * @return Collection */ protected static function createIntermediatePaths(Collection $paths): Collection { return $paths ->flatMap(function (string $path) { $pathParts = Str::of($path)->explode('.'); return $pathParts->map( fn (string $pathPart, int $index) => $pathParts ->slice(0, $index + 1) ->join('.'), ); }) ->unique(); } }