tenanted.dev v0.1.5
laravel-tenanted 0.1.5 on crates.io

Database-per-tenant
for Laravel for Rust.

Rails' activerecord-tenanted ergonomics with vanilla laravel-rust models, fail-closed safety, and zero tenant_id columns.

Try Live Demo Read the Docs

One line to turn it on.
Zero lines in your models.

.with_tenancy() wires the resolver, TrustHosts, the fail-closed database guard, a tenant-prefixed cache store, and five tenant:* Artisan commands. Your controllers, models and Route Model Binding stay exactly as laravel-rust wrote them.

  • Subdomain, header, signed-session, or custom resolution
  • Tenant and Option<Tenant> extractors
  • Route Model Binding returns 404 across tenants
Getting started
src/main.rs
use std::process::ExitCode;
use laravel_tenanted::WithTenancy;

fn main() -> ExitCode {
    laravel::Application::configure()
        .with_tenancy()
        .with_routing(|routing, _| {
            routing.routes(|route| {
                route.get("/invoices", list_invoices);
                route.get("/invoices/{invoice}", show_invoice);
            });
        })
        .run()
}
How isolation works

Every customer gets their own database. Nothing else changes.

01

Physical database per tenant

Each tenant gets a named pool (tenant_acme) registered on first touch. DatabaseManager::using_connection routes every #[model], db::table() and transaction inside the request's async task, with no global mutation, so concurrent tenants never race.

Under the hood
02

Fail-closed by default

require_tenant() points the default connection at an undefined sentinel. A query that escapes a tenant scope errors immediately instead of reading the wrong database. Tenant IDs are sanitized before they touch a URL or a path.

Security model
03

Full-stack scoping

Cache keys become tenant:{id}:…, files land under tenants/{id}/…, queued jobs restore their tenant via laravel::context, and every structured log line carries tenant="acme".

Queues, cache & storage
04

Storage-agnostic

Swap one URL template to move between local SQLite, PostgreSQL, MySQL, or LiteVault (SQLite on S3/R2 with per-tenant encryption).

SQLitePostgresMySQLLiteVault
Deployment guide
Battle-tested

Verified end-to-end against real infrastructure. No mocks.

SQLite tenants on 16 LRU pools
500
Random-access throughput, p50 3.4 ms
2,653 req/s
Live LRU evictions under load
5,840
Resident memory, 65 open FDs
43.8 MiB
Errors and leaks, 500/500 verified
0 / 0
SIGKILL mid-load169/169 acked rows survived; integrity_check = ok on all 11 DBs
Two processes, one directory640 cross-process ops, 0 SQLITE_BUSY
Verified live onPostgreSQL 15.1 · MySQL 8.0.31 · Redis/Valkey · S3 (RustFS) · SQLite · LiteVault
Live demo

Click through it before you cargo add it.

A laravel-rust + Inertia + React app running on Laravel Cloud, with an org switcher built from the Inertia guide. Sign in as any persona in one click and watch each organization's data stay in its own database.

Open demo.tenanted.dev
Central data

Shared tables name their connection once.

Users, plans and memberships live in a central database. Pin the model and it ignores the tenant override everywhere.

Models, migrations & central data
src/models.rs
#[model(connection = "central")]
pub struct BillingPlan { pub id: i64, pub name: String }