Download the PHP package aventure-cloud/laravel-tenancy without Composer
On this page you can find all versions of the php package aventure-cloud/laravel-tenancy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aventure-cloud/laravel-tenancy
More information about aventure-cloud/laravel-tenancy
Files in aventure-cloud/laravel-tenancy
Package laravel-tenancy
Short Description Single database Multi-Tenancy solution for Laravel applications
License MIT
Informations about the package laravel-tenancy
Laravel Multi Tenancy
Single database Multi-Tenancy solution for Laravel applications.
- Author: Valerio Barbera - [email protected]
- Author Website: www.gistmetrics.com
Installation
composer require aventure-cloud/laravel-tenancy
After installation you don't need to add MultiTenancyServiceProvider
in your configuration because it's auto-discovered from Laravel.
Configuration
To get full control of the package's behavior you need publish config/multitenancy.php
file.
php artisan vendor:publish --provider="AventureCloud\MultiTenancy\MultiTenancyServiceProvider"
Eloquent Model Traits
Attach BelongsToTenant
trait to models that you want scope by tenant:
Add IsTenant
trait to your eloquent model that represent the tenant entity in your app:
Configuring multi-tenant routes
You need to wrap all routes with tenant dependency before applying any other middleware. You can use the routes method by our facade that handle tenant recognition process automatically for you.
Default routes
Your landing page need to be loaded under your personal url, so you need to tell to the laravel how to identify
your general routes. In your RoutesServiceProvider
you can modify your map
method like:
Validation Rules
Scoping your application by tenant can cause wrong behavior of the unique
and exists
validation rules
that performs a query on the database without considering tenant scope by default.
This package ships with extended version of these two rules that run a query filtered by tenant.
Queue
One drawback of sending Jobs into the Queue is that these are executed in a completely different process depending on your queue configuration including redis and beanstalk.
In order to assist you with tenant aware jobs, a TenantAwareJob
is available to you.
Instead of applying the SerializesModel
trait as per suggestion in the Laravel documentation, you should use this Trait instead.
Events
When a tenant is founded and stored in Tenancy service the package fire an event with attacched tenant instance:
TenantLoaded
LICENSE
This package are licensed under the MIT license.