简体   繁体   中英

Implicit route binding issue after upgraded from Laravel 5.2 to 5.3

I just upgraged my Laravel project from 5.2 to 5.3 with Shift . After manually merging the files Shift couldn't merge I opened up a tab and went to my project. And it seems that route model binding doesn't work correctly.

I use a sluggable package.

Route::get('team/{team}', function (App\Models\Team $team) {
    dd($team);
});

But when I use the code above with a slug or an id, I just get a new model instance instead of the associated model. Even if I remove the sluggable trait from the model and use a ID in the route. 404 page doesn't display when I use an id which not exists.

I'm not sure what causes the error, any ideas? Cheers.

\\Illuminate\\Routing\\Middleware\\SubstituteBindings::class到中间件后修复。

If you run into the same issue upgrading from 5.2, then check your Kernel file against the 5.3 version: https://github.com/laravel/laravel/blob/5.3/app/Http/Kernel.php

\\Illuminate\\Routing\\Middleware\\SubstituteBindings::class should be included in protected $middlewareGroups under 'web' . Probably the safest option would be to copy the whole Kernel from github so you don't miss anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM