我可以在Laravel的路由组中将多个域分组吗? [英] Can I group multiple domains in a routing group in Laravel?
本文介绍了我可以在Laravel的路由组中将多个域分组吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下内容:
Route::group(array('domain' => array('admin.example.com')), function()
{
...
});
Route::group(array('domain' => array('app.example.com')), function()
{
...
});
Route::group(array('domain' => array('dev.app.example.com')), function()
{
...
});
有没有办法让多个域共享一个路由组?像这样:
Is there any way to have multiple domains share a routing group? Something like:
Route::group(array('domain' => array('dev.app.example.com','app.example.com')), function()
{
...
});
推荐答案
Laravel似乎不支持此功能.
Laravel does not seem to support this.
我不确定为什么我不早想到这一点,但是我想一种解决方案是只在一个单独的函数中声明路由,然后将其传递给两个路由组.
I'm not sure why I didn't think of this sooner, but I guess one solution would be to just declare the routes in a separate function as pass it to both route groups.
Route::group(array('domain' => 'admin.example.com'), function()
{
...
});
$appRoutes = function() {
Route::get('/',function(){
...
});
};
Route::group(array('domain' => 'app.example.com'), $appRoutes);
Route::group(array('domain' => 'dev.app.example.com'), $appRoutes);
我不确定此解决方案是否会对性能产生重大影响.
I'm not sure if there is any significant performance impact to this solution.
这篇关于我可以在Laravel的路由组中将多个域分组吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文