• Stars
    star
    2,541
  • Rank 18,052 (Top 0.4 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 9 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously github.com/hyn/multi-tenant

Packagist build status codecov Packagist Codacy Badge Join our Discord server Mentioned in Awesome Laravel

The unobtrusive Laravel package that makes your app multi tenant. Serving multiple websites, each with one or more hostnames from the same codebase. But with clear separation of assets, database and the ability to override logic per tenant.

Suitable for marketing companies that like to re-use functionality for different clients or start-ups building the next software as a service.


Offers:

  • Integration with the awesome Laravel framework.
  • Event driven, extensible architecture.
  • Close - optional - integration into the web server.
  • The ability to add tenant specific configs, code, routes etc.

Database separation methods:

  • One system database and separated tenant databases (default).
  • Table prefixed in the system database.
  • Or .. manually, the way you want, by listening to an event.

Complete documentation covers more than just the installation and configuration.

Requirements, recommended environment

  • Laravel 9.0+.
  • PHP 8.0+
  • Apache or Nginx.
  • MySQL, MariaDB, or PostgreSQL.

Please read the full requirements in the documentation.

Installation

composer require hyn/multi-tenant

Automatic service registration

Using auto discovery, the tenancy package will be auto detected by Laravel automatically.

Manual service registration

In case you want to disable webserver integration or prefer manual integration, set the dont-discover in your application composer.json, like so:

{
    "extra": {
        "laravel": {
            "dont-discover": [
                "hyn/multi-tenant"
            ]
        }
    }
}

If you disable auto discovery you are able to configure the providers by yourself.

Register the service provider in your config/app.php:

    'providers' => [
        // [..]
        // Hyn multi tenancy.
        Hyn\Tenancy\Providers\TenancyProvider::class,
        // Hyn multi tenancy webserver integration.
        Hyn\Tenancy\Providers\WebserverProvider::class,
    ],

Deploy configuration

First publish the configuration and migration files so you can modify it to your needs:

php artisan vendor:publish --tag tenancy

Open the config/tenancy.php and config/webserver.php file and modify to your needs.

Make sure your system connection has been configured in database.php. In case you didn't override the system connection name the default connection is used.

Now run:

php artisan migrate --database=system

This will run the required system database migrations.


Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

Contributors


License and contributing

This package is offered under the MIT license. In case you're interested at contributing, make sure to read the contributing guidelines.

Testing

Run tests using:

vendor/bin/phpunit

If using MySQL, use:

LIMIT_UUID_LENGTH_32=1 vendor/bin/phpunit

Please be warned running tests will reset your current application completely, dropping tenant and system databases and removing the tenancy.json file inside the Laravel directory.

Changes

All changes are covered in the changelog.

Contact

Get in touch personally using;

More Repositories

1

tenancy

Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups.
PHP
1,161
star
2

restaurateur.app

The production grade demonstration project for @tenancy; where building a restaurant saas app is made reality.
PHP
30
star
3

laravel-websockets-bridge

Package to bridge the beyondcode/laravel-websockets package to hyn/multi-tenant
PHP
13
star
4

framework

The framework code for @tenancy
PHP
13
star
5

docs

@tenancy documentation markdown files and index.
13
star
6

hyn-nova

The nova toolkit for hyn/multi-tenant.
PHP
12
star
7

affects-views

When @tenancy affects your Laravel views.
PHP
2
star
8

affects-models

When @tenancy affects your Laravel eloquent models.
PHP
2
star
9

multi-tenant-bridge

Provides a bridge between hyn/multi-tenant and @tenancy for those upgrading
PHP
2
star
10

affects-routes

When @tenancy affects your Laravel routes.
PHP
2
star
11

identification-driver-console

The @tenancy identification driver for artisan commands.
PHP
1
star
12

identification-driver-environment

The @tenancy identification driver using environment variables.
PHP
1
star
13

hooks-migration

When @tenancy lifecycle hooks trigger migrations and seeds.
PHP
1
star
14

db-driver-pgsql

1
star
15

affects-logs

When @tenancy affects your Laravel logs.
PHP
1
star
16

hooks-database

When @tenancy lifecycle hooks trigger creation, updates and deletion of tenant databases.
PHP
1
star
17

affects-broadcasts

When @tenancy affects your Laravel broadcasts.
PHP
1
star
18

affects-configs

When @tenancy affects your Laravel config.
PHP
1
star
19

affects-urls

When @tenancy affects your Laravel tenant URL.
PHP
1
star
20

affects-connections

When @tenancy affects your Laravel database connections.
PHP
1
star
21

identification-driver-http

The @tenancy identification driver for http
PHP
1
star
22

tenancy-ci-images

Shell
1
star
23

db-driver-mysql

@tenancy db adapter for mysql based databases.
PHP
1
star
24

affects-filesystems

When @tenancy affects your Laravel filesystem.
PHP
1
star
25

hooks-hostname

PHP
1
star