public static function toKeyIndex($collection, $key, $useDotSyntax = false)
    {
        $keyIndexArray = [];
        foreach ($collection as $item) {
            $itemArray = is_array($item) ? $item : (method_exists($item, 'toArray') ? $item->toArray() : []);
            $keyValue = self::get($itemArray, $key, null, $useDotSyntax);
            $keyIndexArray[$keyValue] = $itemArray;
        }

        return $keyIndexArray;
    }