apsg/multisite

Package for laravel multisite feature (multiple installations)

0.1.0 2019-12-18 18:08 UTC

This package is auto-updated.

Last update: 2024-10-19 05:23:11 UTC


README

Latest Version on Packagist Total Downloads Build Status StyleCI Status

Package for managing multiple installations of the same code base. It gives the ability to change the views depending on the "domain" but preserving the backend core the same.

It also lets you to define domain-specifig config.

Installation

Via Composer

composer require apsg/multisite

Usage

After the installation:

Add your domain to your .env file, i.e.:
MULTISITE_DOMAIN=test
Add view folder

Create new view folder for your domain:

mkdir resources/views/test

And that's it! From now on the Laravel's view engine would look for view files in main view directory (resources/views/) as well as in domain-specific directory (resources/views/test in the example above).

Config files and helpers

The package provides helper Facade through which one can access domain-specific configurations. One can publish default config file using:

php artisan vendor:publish --tag=multisite.config

The helper:

\Multisite::config('some.key');

would return config equivallent to:

config('multisite.{current_domain}.some.key');
Current domain helper

To check current domain use the Facade helper:

\Multisite::domain();

Multisite assets

To compile your assets in your webpack.mix.js add something like that:

// ----- MULTISITE -----------------
let domains = [
    'site1',
    'site2'
];

for (let domain of domains) {
    mix.js('resources/assets/js/' + domain + '.js', 'public/js', domain + '.js')
        .sass('resources/assets/sass/' + domain + '.scss', 'public/css', domain + '.css');
}

This will search automatically for files resources/js/{domain}.js and resources/sass/{domain}.scss, compile them and move them to directories public/js/{domain}.js and public/css/{domain}.css respectively.

Then one can use helpers provided with this package to automagically load in your layout file only domain-related files:

    <link href="{{ multisite_css() }}" rel="stylesheet">
    <script src="{{ multisite_js() }}"></script>

Testing

composer test

License

license. Please see the license file for more information.