larvel 路由未生效,Laravel 5.5路由中的模型绑定不起作用

In my routes.php I have this:

Route::get('user/{user}/permissions/','UserController@permissions')->name('user.permissions');

In my controller I have:

public function permissions(User $user){

dd($user);

}

$user is empty object (like new user; without attributes)

if I use:

public function permissions($user){

dd(User::find($user));

}

Works perfectly!!

I have previously Laravel 5.2 and this code works fine but in Laravel 5.5 it doesn't work, any ideas why?

解决方案

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

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.

"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,

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

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

..."

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值