当我想在 laravel 5.8 中使用模型绑定时出现此错误

i have this error when i want tu use model binding in laravel 5.8

路由服务提供商

public function boot(Router $router)
    {
        parent::boot($router);

        $router->model('article','App\article');
    }

web.php

Route::resource('article','articleController');

控制器

public function show(Article $article)
    {

        /*$article=Article::find($id);*/

        if(!$article){

            abort(404);

        }

        return view('article.show ',compact('article'));

Declaration of App\Providers\RouteServiceProvider::boot(App\Providers\Router $router) should be compatible with Illuminate\Foundation\Support\Providers\RouteServiceProvider::boot()

您的问题来自 PHP 继承。重写方法时,必须保持与父方法相同的签名(__construct 除外)。 Laravel 服务提供者的 boot 方法是通过容器调用的,所以你可以使用依赖注入,但在这种情况下不能,因为 App\Providers\RouteServiceProvider 继承自另一个已经有 boot 方法定义。 在您的情况下,由于

,您需要从签名中删除 Router 并从方法内容中检索它
$router = $this->app['router'];