Laravel5`RouteServiceProvider`应该与`错误兼容 [英] Laravel5 `RouteServiceProvider` `should be compatible with` Error
问题描述
我正在开发Laravel5的Web应用程序,并用Controller的代码编写了下面的代码.
I am developing a web application by Laravel5, and in code of Controller, I wrote a code bellow.
public function show($id)
{
$post = Post::find($id);
\View::share(compact('post'));
return view('posts.show');
}
但是,我想写如下.
public function show(Post $post)
{
\View::share(compact('post'));
return view('posts.show');
}
在RouteServiceProvider.php
中,我添加了Router $router
public function boot(Router $router)
{
但是,它不起作用,并且在下面显示错误消息.
but, it doesn't work, and I got an error bellow.
声明 App \ Providers \ RouteServiceProvider :: boot(App \ Providers \ Router $ router) 应该与 Illuminate \ Foundation \ Support \ Providers \ RouteServiceProvider :: boot()
Declaration of App\Providers\RouteServiceProvider::boot(App\Providers\Router $router) should be compatible with Illuminate\Foundation\Support\Providers\RouteServiceProvider::boot()
什么问题? 谢谢!
推荐答案
您使用的是哪个laravel
版本?
在低于5.3的版本中,您必须编写如下内容.
In version newer than 5.3, you have to write as follows.
public function boot()
{
//
parent::boot();
Route::model('post', \App\Post::class);
}
参考:
https://readouble.com/laravel/5.3/en/routing.html
https://readouble.com/laravel/5.2/en/routing.html
Explicit Binding
部分.
这篇关于Laravel5`RouteServiceProvider`应该与`错误兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!