Laravel 5. *子域中的根路径

时间:2015-07-12 18:46:00

标签: laravel laravel-5 laravel-routing

我有基域路由和子域路由。例如,如果我请求import npyscreen as np class myPop(np.NPSApp): def setopt(self, title, oList, multi): self.title = title self.options = oList self.multi = multi self.height = len(self.options)+1 def main(self): F = np.Popup(name="Choose an option") if self.multi: opt = F.add(np.TitleMultiSelect, name=self.title, max_height=self.height, values=self.options, scroll_exit=True) else: opt = F.add(np.TitleSelectOne, name=self.title, max_height=self.height, values=self.options, scroll_exit=True) F.edit() self._values = opt.get_selected_objects() self.result = ( self._values if self.multi and len(self._values) > 1 else self._values[0] ) def ChooseOption(title, oList, multi=False): pop = myPop() pop.setopt(title, oList, multi) pop.run() return pop.result # Show a popup with radiobuttons to select 1 item from a list print ChooseOption('choose a single element', ['a','b','c','d']) # Show a popup with radiobuttons to multi-select items from a list print ChooseOption('choose multi-elements', ['a','b','c','d'], True) ,它将返回正确答案。但是,如果我想请求subdomain.example.com/test,它将从根域执行代码。

subdomain.example.com

1 个答案:

答案 0 :(得分:1)

更改顺序将有所帮助 - Laravel按顺序保留路线,并逐个检查路线,因此通过将子路径的路线移动到首先找到并使用的主要路线之上,将全局路线作为后备对于其他领域。

Route::group(['domain' => 'subdomain.example.com'], function()
{
    Route::get('/', function() {
        // How to request this part?
    });

     Route::get('/test', function() {
        // Works
    });
}

Route::get('/', function() {
    // Main 
});

Route::get('/path', function() {
    // .. 
});