public function setMiddleware($middleware)
    {
        if ($this->lock) {
            throw new Exception('Route cannot be modified');
        }

        $curMiddleware = [];
        if (is_array($middleware)) {
            $curMiddleware = $middleware;
        } else {
            $args = func_get_args();
            foreach ($args as $arg) {
                if (is_string($arg)) {
                    $curMiddleware[] = $arg;
                }
            }
        }

        //Add group middleware if any
        $this->middleware = (new Collection(Router::$groupsProps['middleware']))
                        ->flatten()->toArray();
        foreach ($curMiddleware as $value) {
            if (in_array($value, $this->middleware)) {
                continue;
            }
            $this->middleware[] = $value;
        }

        return $this;
    }