protected static function flattenArray(array $array, int $depth = PHP_INT_MAX): array
    {
        $items = [];

        foreach ($array as $item) {
            if ($item instanceof self) {
                $item = $item->all();
            }

            if (is_array($item)) {
                if ($depth === 1) {
                    $items = array_merge($items, $item);
                    continue;
                }
                $items = array_merge($items, static::flattenArray($item, $depth - 1));
                continue;
            }

            $items[] = $item;
        }

        return $items;
    }