在 Router.php 第 366 行:传递给 Illuminate\Routing\Router::group() 的参数 1 必须是数组类型,

Mat*_*gni 4 graphql-php laravel-5.7 laravel-5.8 laravel-lighthouse

我已经从to更新了Laravel,现在我的应用程序无法运行。v5.7v5.8

我因为这个问题更新了它:composer require rebing/graphql-laravel failed

我解决了包不兼容问题,但现在 Laravel 崩溃了:

$ php artisan serve

In Router.php line 366:

  Argument 1 passed to Illuminate\Routing\Router::group() must be of the type array, string given, called in /var/www/masvino/Server-bak/vendor/laravel/framework/src/Illuminate/Support/Facades  
  /Facade.php on line 239
Run Code Online (Sandbox Code Playgroud)

我怀疑 Laravel 的团队改变了这种方法的坚定性:

照亮\路由\Router.php

    /**
     * Create a route group with shared attributes.
     *
     * @param  array  $attributes
     * @param  \Closure|string  $routes
     * @return void
     */
    public function group(array $attributes, $routes) // line 366
    {
        $this->updateGroupStack($attributes);

        // Once we have updated the group stack, we'll load the provided routes and
        // merge in the group's attributes when the routes are created. After we
        // have created the routes, we will pop the attributes off the stack.
        $this->loadRoutes($routes);

        array_pop($this->groupStack);
    }
Run Code Online (Sandbox Code Playgroud)

这是我的composer.json文件的当前内容:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "^5.8.0",
        "laravel/tinker": "^1.0",
        "mll-lab/laravel-graphql-playground": "^1.1.0",
        "nuwave/lighthouse": "^4.4.2",
        "spatie/laravel-cors": "^1.6",
        "webonyx/graphql-php": "^0.13.8",
        "rebing/graphql-laravel": "2.1.1" 
    },
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [],
            "providers": [
                "Rebing\\GraphQL\\GraphQLServiceProvider"
            ],
            "aliases": {
                "GraphQL": "Rebing\\GraphQL\\Support\\Facades\\GraphQL"
            }
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}
Run Code Online (Sandbox Code Playgroud)

我认为问题可能出在这个文件中: app/Providers/RouteServiceProvider.php

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "^5.8.0",
        "laravel/tinker": "^1.0",
        "mll-lab/laravel-graphql-playground": "^1.1.0",
        "nuwave/lighthouse": "^4.4.2",
        "spatie/laravel-cors": "^1.6",
        "webonyx/graphql-php": "^0.13.8",
        "rebing/graphql-laravel": "2.1.1" 
    },
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [],
            "providers": [
                "Rebing\\GraphQL\\GraphQLServiceProvider"
            ],
            "aliases": {
                "GraphQL": "Rebing\\GraphQL\\Support\\Facades\\GraphQL"
            }
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}
Run Code Online (Sandbox Code Playgroud)

不知道现在哪个是方法的正确格式group()。有人可以帮我解决这个问题吗?提前致谢!

小智 8

正如错误消息所暗示的,通过在 web.php 文件中添加一个空数组来解决问题。

Route::group([], function () {
   Route::get('/', 'HomeController@index')->name('home');
});
Run Code Online (Sandbox Code Playgroud)

我正在使用 Laravel v7。


小智 0

你可以在你的routes/web.php中使用

Route::group( ['prefix' => 'backend','middleware' => ['auth', 'admin']], function() {}
Run Code Online (Sandbox Code Playgroud)