protected function checkRegexRecursively($array, $pattern, $accessKey = null)
    {
        $found = [];

        if (!is_array($array) && !is_object($array)) {
            return [];
        }

        if ($array instanceof Collection || $array instanceof Model) {
            $array = $array->toArray();
        }

        foreach ($array as $index => $value) {
            $newAccessKey = ($accessKey ? $accessKey.'.' : '').$index;

            if (preg_match($pattern, $newAccessKey, $matches)) {
                $found[] = $matches;
            }

            $found = array_merge($found, $this->checkRegexRecursively($value, $pattern, $newAccessKey));
        }

        return $found;
    }