Download the PHP package rylxes/laravel-multitenancy without Composer

On this page you can find all versions of the php package rylxes/laravel-multitenancy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-multitenancy

Laravel Multitenancy

Full Documentation — Complete usage guide, configuration reference, and API docs.

Latest Version on Packagist Total Downloads License PHP Version

Simple, safe multi-tenancy for Laravel. Single-database by default, multi-database when you need it.

Why This Package?

Pain Point Solution
Data leakage between tenants BelongsToTenant trait + safeguard mode throws on unscoped queries
Cache pollution PrefixCacheTask auto-prefixes cache keys per tenant
Storage file mixing PrefixFilesystemTask isolates disk paths per tenant
Queue jobs losing context First-class integration with laravel-tenant-jobs
No fail-safe for missing scopes Safeguard throws NoCurrentTenantException on unscoped queries
Migration complexity tenant:migrate runs migrations across all tenants
Testing difficulty ActingAsTenant trait for clean test setup
No CLI tenant management 6 artisan commands out of the box

Requirements

Installation

Publish config and run migrations:

Quick Start (5 Minutes)

1. Create a tenant

2. Add tenant_id to your models' tables

3. Use the BelongsToTenant trait

That's it. All queries on Project are now automatically scoped to the current tenant, and tenant_id is auto-filled on creation.

4. Add middleware to your routes

Tenant Identification

The package resolves tenants from incoming requests. Choose a strategy in config/multitenancy.php:

Finder How it works Best for
DomainTenantFinder Matches request->getHost() Custom domains (acme.com)
SubdomainTenantFinder Extracts first subdomain part SaaS subdomains (acme.app.com)
PathTenantFinder Uses first URL segment Path-based (app.com/acme/...)
HeaderTenantFinder Reads X-Tenant-ID header APIs and SPAs

Data Isolation

BelongsToTenant Trait

Add to any Eloquent model to auto-scope all queries and auto-fill tenant_id:

Safeguard Mode

When safeguard is true (default), the package throws NoCurrentTenantException if you query a tenant-scoped model without an active tenant. This prevents accidental data leakage:

Admin/Landlord Queries

Bypass tenant scoping when needed:

Cache & Storage Isolation

Enabled by default via switch tasks:

Multi-Database Support

Uncomment SwitchDatabaseTask in config and set your tenant's database field:

Programmatic Usage

Artisan Commands

Command Description
tenant:list List all tenants
tenant:create {name} Create a tenant (--domain=, --database=)
tenant:delete {id} Delete a tenant (with confirmation)
tenant:migrate Run migrations for all tenants (--tenant= for one)
tenant:seed Seed databases for all tenants
tenant:artisan {command} Run any artisan command for all tenants

Events

Event When
TenantMadeCurrent After a tenant is set as current
TenantForgotten After tenant context is cleared
TenantCreated After a new tenant is created
TenantDeleted After a tenant is deleted

Queue Jobs

For tenant-aware queue jobs, install laravel-tenant-jobs:

Zero-config integration — laravel-tenant-jobs auto-detects this package and handles tenant context in all queued jobs, batch callbacks, retries, scheduled tasks, and notifications.

Testing

Use the ActingAsTenant trait in your tests:

Configuration Reference

Architecture

License

MIT. See LICENSE.


All versions of laravel-multitenancy with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/console Version ^10.0|^11.0|^12.0
illuminate/events Version ^10.0|^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rylxes/laravel-multitenancy contains the following files

Loading the files please wait ...