Elham Hosseini
Elham Hosseini

Reputation: 33

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

RouteServiceProvider

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

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

web.php

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

controller

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

Upvotes: 1

Views: 57

Answers (1)

Shizzen83
Shizzen83

Reputation: 3529

Your issue comes from PHP inheritance. When you override a method, you have to keep the same signature than the parent method (except for __construct). The boot method of Laravel service provider is called through the container, so you can use Dependency Injection, but not in this case because App\Providers\RouteServiceProvider inherits from another service provider which already has a boot method defined. In your case, you need to remove the Router from the signature and retrieve it from the method content thanks to

$router = $this->app['router'];

Upvotes: 3

Related Questions