Laravel5 `RouteServiceProvider` `should be compatible with` Error

前端 未结 3 1519
挽巷
挽巷 2021-01-06 03:21

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);
            


        
相关标签:
3条回答
  • 2021-01-06 03:34

    What laravel version do you use?

    In version newer than 5.3, you have to write as follows.

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

    Reference:

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

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

    Explicit Binding section.

    0 讨论(0)
  • 2021-01-06 03:52

    You should try like:

    Please put use Route; instead of use App\Providers\Router; and try

    Or you can also use the app('router')->pattern().

    For more details please follow this link.

    0 讨论(0)
  • 2021-01-06 03:54

    boot method is inherited from Illuminate\Foundation\Support\Providers\RouteServiceProvider which doesn't have the same signature as yours which is causing this error.

    If you have to use the router inside boot method then use app() helper function to get the instance of the router.

    public function boot()
    {
        $router = app('router'); // Router Instance
    
        parent::boot();
    }
    
    0 讨论(0)
提交回复
热议问题