Weblurk
Weblurk

Reputation: 6822

Multiple sites in one Laravel installation?

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

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.

Upvotes: 0

Views: 2597

Answers (2)

Vinod saraswat
Vinod saraswat

Reputation: 25

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

Upvotes: 1

Hieu Le
Hieu Le

Reputation: 8415

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

Upvotes: 1

Related Questions