且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel 5.5路由中的模型绑定不起作用

更新时间:2023-02-21 17:46:10

您的声音从5.2升级到了某些版本.

Sounds like you upgraded from 5.2 up to ... some version.

Laravel 5.3使用SubstitueBindings中间件进行隐式和显式绑定,不再在中间件堆栈之前通过路由器完成

Laravel 5.3 uses the SubstitueBindings middleware to do the implicit and explicit bindings, it is no longer done via the router before the middleware stack.

如果您升级了该中间件并且未将其添加到任何组中,则将没有路由模型绑定,因为中间件负责用绑定替换参数.

If you upgraded and did not add this middleware to any of the groups, you will not have your route model bindings as the middleware is responsible for substituting the parameter with the binding.

路由模型绑定现在已使用中间件完成.所有应用程序都应将Illuminate\Routing\Middleware\SubstituteBindings添加到app/Http/Kernel.php文件中的web中间件组中:

"Route model binding is now accomplished using middleware. All applications should add the Illuminate\Routing\Middleware\SubstituteBindings to your web middleware group in your app/Http/Kernel.php file:

\Illuminate\Routing\Middleware\SubstituteBindings::class,

您还应该在HTTP内核的$routeMiddleware属性中注册用于绑定替换的路由中间件:

You should also register a route middleware for binding substitution in the $routeMiddleware property of your HTTP kernel:

'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, ..."

Laravel 5.3文档-升级-中间件-绑定替代中间件