<?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'
;
protected
$backendNamespace
;
protected
$frontendNamespace
;
protected
$apiNamespace
;
protected
$currentDomain
;
public
function
boot(Router
$router
)
{
$this
->backendNamespace =
'App\Http\Controllers\Backend'
;
$this
->frontendNamespace =
'App\Http\Controllers\Frontend'
;
$this
->apiNamespace =
'App\Http\Controllers\API'
;
$this
->currentDomain = isset(
$_SERVER
[
'HTTP_HOST'
]) ?
$_SERVER
[
'HTTP_HOST'
] :
""
;
parent::boot(
$router
);
}
public
function
map(Router
$router
)
{
$backendUrl
= config(
'route.backend_url'
);
$frontendUrl
= config(
'route.frontend_url'
);
$apiUrl
= config(
'route.api_url'
);
switch
(
$this
->currentDomain){
case
$apiUrl
:
$router
->group([
'domain'
=>
$apiUrl
,
'namespace'
=>
$this
->apiNamespace],
function
(
$router
) {
require
app_path(
'Http/routes-api.php'
);
}
);
break
;
case
$backendUrl
:
$router
->group([
'domain'
=>
$backendUrl
,
'namespace'
=>
$this
->backendNamespace],
function
(
$router
) {
require
app_path(
'Http/routes-backend.php'
);
}
);
break
;
default
:
$router
->group([
'domain'
=>
$frontendUrl
,
'namespace'
=>
$this
->frontendNamespace],
function
(
$router
){
require
app_path(
'Http/routes-frontend.php'
);
}
);
break
;
}
}
}