Skip to content

Instantly share code, notes, and snippets.

@kohenkatz
Created April 14, 2016 18:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohenkatz/4348a9ebab7442a8867021641c7e6364 to your computer and use it in GitHub Desktop.
Save kohenkatz/4348a9ebab7442a8867021641c7e6364 to your computer and use it in GitHub Desktop.
<?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