0

I'm new to Laravel and what I want to accomplish:

  • One laravel installation for multiple sites

  • Have some functions shared amongst all my sites, for instance User handling, while other functionality will be unique to a specific site

I want to pretty much have a wide variety of different sites under one installation, so I then can build an admin view where I can manage all sites.

How would I go about doing this? I have a fresh Laravel 4.2 installation.

Weblurk
  • 6,562
  • 18
  • 64
  • 120

2 Answers2

1

You can have a look at the package rbewley4/multi-app-laravel on Github. Another hint can be found at this answer on StackOverflow

Community
  • 1
  • 1
Hieu Le
  • 8,288
  • 1
  • 34
  • 55
1

1. Create ConfigServiceProvider in app\Providers folder and set code:

namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Request;

class ConfigServiceProvider extends ServiceProvider {
    public function register() {

        $template = $_SERVER["SERVER_NAME"];

        $config = app('config');
        $config->set('template', $template);
    }
}

2. Create TemplateServiceProvider in app\Providers folder and set code:

namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\FileViewFinder;
use Illuminate\View\ViewServiceProvider;
class TemplateServiceProvider extends ViewServiceProvider {
    public function registerViewFinder() {
        $this->app->bind('view.finder', function ($app) {
            $template = $app['config']['template'];
                    if(file_Exists(realpath(base_path('themes/'.$template.'/views')))){
        $paths = [realpath(base_path('themes/'.$template.'/views'))];
    }else{
        $paths = $app['config']['view.paths'];
    }
            return new FileViewFinder($app['files'], $paths);
        });
    }
}

3. Set providers in config/app.php :

App\Providers\ConfigServiceProvider::class,
    App\Providers\TemplateServiceProvider::class,

4. Create your template forders > themes/{your_domain_name}/views