HTTP routing 可以动态添加吗?一起来看看
看了一个第三方'Mews\Captcha的库,其中provider这么写的
// HTTP routing
if (strpos($this->app->version(), 'Lumen') !== false) {
$this->app->get('captcha[/{config}]', 'Mews\Captcha\LumenCaptchaController@getCaptcha');
} else {
if ((double) $this->app->version() >= 5.2) {
$this->app['router']->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha')->middleware('web');
} else {
$this->app['router']->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha');
}
}
疑问是:发布之后,web下面的web.php并没有新增路由配置。事实上,路由(captcha/{config?})生效了,如何做到的呢?
关于 LearnKu
你贴的这段代码就是把路由注册了啊
laravel的核心概念服务容器了解一下,这里的$this->app['router']就等于你web.php里面的Route