Laravel中间件增强了路由模型绑定的安全性

时间:2016-12-14 01:20:26

标签: laravel ioc-container middleware

任何人都可以想到一种灵活的中间件方式或者如果'如果'声明,以便我们可以更安全地使用路由模型绑定?

Route::get('/channel-groups/{channelGroup}/channels/{channel}', [
    'as'   => 'channel-groups',
    'uses' => function(\App\Distribution\UserConfigurations\ChannelGroup $channelGroup, \App\Distribution\UserConfigurations\Channel $channel){

        //@todo: middleware
        if(!$channelGroup->Channels->contains($channel)){
            return abort(401, 'Unauthorized');
        }

        return $channel;
    }
]);

0 个答案:

没有答案