protected function toDbType($value, $type)
    {
        switch ($type) {
            case 'int':
                return (int) $value;

            case 'bool':
                return (bool) $value;

            case 'string':
            case 'datetime': // Coverts by database
            case 'date':
            case 'float':
                return (string) $value;

            case 'array':
            case 'json':
                return json_encode((array) $value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

            default:
                throw new InvalidArgumentException('Unsupported cast type: ' . $type);
        }
    }