Laravel5`RouteServiceProvider`应该与错误兼容

hie*_*el 5 php laravel

我正在开发Laravel5的Web应用程序,并在Controller的代码中编写了以下代码。

public function show($id)
{
    $post = Post::find($id);
    \View::share(compact('post'));
    return view('posts.show');
}
Run Code Online (Sandbox Code Playgroud)

但是,我想写如下。

public function show(Post $post)
{
    \View::share(compact('post'));
    return view('posts.show');
}
Run Code Online (Sandbox Code Playgroud)

在中RouteServiceProvider.php,我添加了Router $router

public function boot(Router $router)
{
Run Code Online (Sandbox Code Playgroud)

但是,它不起作用,并且出现错误提示。

App \ Providers \ RouteServiceProvider :: boot的声明(App \ Providers \ Router $ router)应与Illuminate \ Foundation \ Support \ Providers \ RouteServiceProvider :: boot()兼容

怎么了 谢谢!

小智 4

laravel你用什么版本?

在5.3以上的版本中,你必须这样写。

public function boot()
{
    //
    parent::boot();
    Route::model('post', \App\Post::class);
}
Run Code Online (Sandbox Code Playgroud)

参考:

https://readouble.com/laravel/5.3/en/routing.html

https://readouble.com/laravel/5.2/en/routing.html

Explicit Binding部分。