Created
April 14, 2016 18:54
-
-
Save kohenkatz/4348a9ebab7442a8867021641c7e6364 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Illuminate\Routing\Router; | |
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; | |
class RouteServiceProvider extends ServiceProvider | |
{ | |
protected $namespace = 'App\Http\Controllers'; | |
public function boot(Router $router) | |
{ | |
parent::boot($router); | |
} | |
public function map(Router $router) | |
{ | |
// Each route subdomain of the application has its own routes file, and its own sub-Namespace, | |
// as well as its own list of middleware. | |
// To allow for setting different domains for testing, the domains come from `.env` via a config file. | |
$router->group(['namespace' => $this->namespace], function ($router) { | |
$this->register_domain($router, 'Activate', config('domains.activate'), ['cors', 'api']); | |
$this->register_domain($router, 'Client', config('domains.client'), ['web', 'auth']); | |
$this->register_domain($router, 'Login', config('domains.login'), ['cors', 'api']); | |
$this->register_domain($router, 'Newsletter', config('domains.newsletter'), ['web']); | |
}); | |
} | |
protected function register_domain(Router $router, $namespace, $domain, $middleware) | |
{ | |
$lcNamespace = snake_case($namespace); | |
$router->group([ | |
'namespace' => $namespace, | |
'domain' => $domain, | |
'as' => "{$lcNamespace}::", | |
'middleware' => $middleware, | |
], function () use ($lcNamespace) { | |
require app_path("Http/routes/{$lcNamespace}.php"); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment