2016-01-13 268 views
0

我有一個問題得到了stucked。爲路由創建文件夾併爲不同的路由定義不同的文件。像我有3種類型的用戶。 admin,user1,user2。我想爲路線創建3個不同的子文件夾。我seacrh谷歌和實施這一點。但它不起作用。 任何人都可以幫助我。laravel中的多路徑文件5 /多個路徑文件夾

感謝

<?php namespace App\Providers; 

use Illuminate\Routing\Router; 
use File; 
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; 

class RouteServiceProvider extends ServiceProvider { 

    /** 
    * This namespace is applied to the controller routes in your routes file. 
    * 
    * In addition, it is set as the URL generator's root namespace. 
    * 
    * @var string 
    */ 
    protected $namespace = 'App\Http\Controllers'; 

    /** 
    * Define your route model bindings, pattern filters, etc. 
    * 
    * @param \Illuminate\Routing\Router $router 
    * @return void 
    */ 
    public function boot(Router $router) 
    { 
     parent::boot($router); 

     // 
    } 

    /** 
    * Define the routes for the application. 
    * 
    * @param \Illuminate\Routing\Router $router 
    * @return void 
    */ 
    public function map(Router $router) 
    { 
     $router->group(['namespace' => $this->namespace], function($router) 
     { 
      foreach(File::allFiles(app_path().'/Http/Routes') as $route) { 
       require_once $route->getPathname(); 
      } 
     }); 
    } 
} 
+0

你所說的「文件夾」是什麼意思?您想要將路線保存在單獨的文件/文件夾中?你想單獨的「文件夾」的網址? –

回答

1

它可以幫助別人:

我有服務從單一的Laravel應用4子域多租戶應用程序。我想保留每個子域的路由在單獨的文件中。

基於公認的答案,在Laravel 5.4我修改了RouteServiceProvider.php,如下mapWebRoutes()方法:

protected function mapWebRoutes() 
{ 
    Route::group([ 
     'middleware' => 'web', 
     'domain' => 'subdomain1.yoursba.com', 
     'namespace' => $this->namespace, 
    ], function ($router) { 
     require base_path('routes/subdomain1Routes.php'); 
    }); 

    Route::group([ 
     'middleware' => 'web', 
     'domain' => 'subdomain2.yoursba.com', 
     'namespace' => $this->namespace, 
    ], function ($router) { 
     require base_path('routes/subdomain2Routes.php'); 
    }); 
}