public static function set($key, $value, $group = 'config', $environment = null, $website_id = null, $type = 'string')
    {
        // Let's check if we are doing special array handling
        $arrayHandling = false;
        $keyExploded   = explode('.', $key);
        if (count($keyExploded) > 1) {
            $arrayHandling = true;
            $key           = array_shift($keyExploded);
            if ($type == 'array') {
                // Use the accessor to ensure we always get an array.
                $value = static::getValueAttribute($value);
            }
        }

        // First let's try to fetch the model, if it exists then we need to do an
        // Update not an insert
        $model = static::where('key', '=', $key)->where('group', '=', $group);

        // Environment can be null or must match.
        if (empty($environment)) {
            $model->whereNull('environment');
        } else {
            $model->where('environment', '=', $environment);
        }

        // Website can be null or must match.
        if (empty($website_id)) {
            $model->whereNull('website_id');
        } else {
            $model->where('website_id', '=', $website_id);
        }

        $model = $model->first();

        if (empty($model)) {

            //Check if we need to do special array handling
            if ($arrayHandling) {
                // we are setting a subset of an array
                $array = [];
                self::buildArrayPath($keyExploded, $value, $array);
                $value = $array;
                $type  = 'array';
            }

            return static::create(
                [
                    'website_id'  => $website_id,
                    'environment' => $environment,
                    'group'       => $group,
                    'key'         => $key,
                    'value'       => $value,
                    'type'        => $type,
                ]);
        }

        //Check if we need to do special array handling
        if ($arrayHandling) {
            // we are setting a subset of an array
            $array = [];
            self::buildArrayPath($keyExploded, $value, $array);

            //do we need to merge?
            if ($model->type == 'array' && ! empty($model->value)) {
                $array = array_replace_recursive($model->value, $array);
            }
            $value = $array;

            $type = 'array';
        }

        $model->value = $value;
        $model->type  = $type;
        $model->save();
        return $model;
    }