Laravel Multi domain Setup Laravel Multi domain Setup laravel laravel

Laravel Multi domain Setup


You should create middle ware to modify path to view folder:

namespace App\Http\Middleware;use Closure;use Illuminate\View\FileViewFinder;use Illuminate\Support\Facades\View;class ModifyViewFolder {  public function handle($request, Closure $next)  {      $finder = new FileViewFinder(app()['files'], [        app_path('../resources/views/' . $request->server->get('HTTP_HOST')),        app_path('../resources/views/'),      ]);      View::setFinder($finder);      return $next($request);  }}

Then register it in Your Kernel.php. This will fallback to default folder if view in domain specific folder does not exists.


I understand this post is rather old, but as with all things Laravel, there is more than one way to do anything. I was able to achieve this effect by overriding the ViewServiceProvider as such. However, this solution will apply to the entire site as the accepted answer will allow you to apply the templating to web groups.

class

 TemplateServiceProvider extends ViewServiceProvider{    /**     * Register the view finder implementation.     *     * @return void     */    public function registerViewFinder()    {        $this->app->bind('view.finder', function ($app) {            $paths = [];            /*             *  Pull our template from our site name             */            $template = Template::where('domain', Request::server('SERVER_NAME'))->first();            if($template)            {                $paths = [                    $app['config']['view.paths.templates'] . DIRECTORY_SEPARATOR . $template->tag                ];            }            /*             *  Default view path is ALWAYS last             */            $paths[] = $app['config']['view.paths.default'];            return new FileViewFinder($app['files'], $paths);        });    }}