Skip to content

Instantly share code, notes, and snippets.

@ptondereau
Last active March 29, 2016 11:13
Show Gist options
  • Save ptondereau/d126c94b03961253da66 to your computer and use it in GitHub Desktop.
Save ptondereau/d126c94b03961253da66 to your computer and use it in GitHub Desktop.
Laravel redirect sub-domain to a templte
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);
}
}
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);
});
}
}
'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