Last active
March 29, 2016 11:13
-
-
Save ptondereau/d126c94b03961253da66 to your computer and use it in GitHub Desktop.
Laravel redirect sub-domain to a templte
This file contains 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
namespace App\Providers; | |
use Illuminate\Support\ServiceProvider; | |
use Illuminate\Support\Facades\Request; | |
class ConfigServiceProvider extends ServiceProvider { | |
public function register() { | |
switch (Request::server("HTTP_X_FORWARDED_SERVER")) { | |
case 'www.site1.com': | |
$template = 'site1'; | |
break; | |
default: | |
$template = 'site'; | |
break; | |
} | |
$config = app('config'); | |
$config->set('template', $template); | |
} | |
} |
This file contains 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
namespace App\Providers; | |
use \Illuminate\Support\ServiceProvider; | |
class TemplateServiceProvider extends \Illuminate\View\ViewServiceProvider { | |
public function registerViewFinder() { | |
$this->app->bind('view.finder', function ($app) { | |
// Set our view to the path defined in ConfigServiceProvider | |
$template = $app['config']['template']; | |
$paths = $app['config']['view.templates'][$template]; | |
return new \Illuminate\View\FileViewFinder($app['files'], $paths); | |
}); | |
} | |
} |
This file contains 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
'templates' => [ | |
'site' => [ | |
realpath(base_path('resources/templates/site')), | |
], | |
'site1' => [ | |
realpath(base_path('resources/templates/site1')), | |
], | |
], |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment