nexus-scholar/laravel-tenant-sqlite

Laravel package for isolated per-tenant SQLite databases

Maintainers

Package info

github.com/nexus-scholar/laravel-tenant-sqlite

pkg:composer/nexus-scholar/laravel-tenant-sqlite

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-04-24 01:16 UTC

This package is auto-updated.

Last update: 2026-04-24 01:21:30 UTC


README

Latest Version on Packagist Total Downloads Tests PHP Version Require

A robust and secure Laravel package for implementing multi-tenancy using an isolated SQLite database file for each tenant.

Instead of adding a tenant_id column to every table, this package gives each user (or organization) their own dedicated SQLite file. This approach guarantees complete data isolation, trivializes single-tenant backups, and simplifies data portability.

Features

  • 🔒 Absolute Isolation: Tenants physically cannot query each other's data.
  • 📦 Simple Backups: Back up a tenant's entire dataset by copying a single .sqlite file.
  • 🚀 Dynamic Connections: Seamlessly connects Eloquent models to the correct file at runtime.
  • 🛠️ Full Lifecycle Management: Commands to create, migrate, inspect, backup, archive, and purge tenant databases.
  • 🌐 HTTP & Queue Support: Includes middleware to automatically resolve tenants for web requests and background jobs.
  • Pest Tested: Thoroughly tested for complete reliability and data isolation.

Documentation

For a comprehensive guide on getting started, setting up models, and writing migrations, please read our beginner's guide:

📖 Read the Beginner's Guide

For architectural details, consult the docs directory.

Quick Start

Installation

composer require nexus-scholar/laravel-tenant-sqlite
php artisan tenant-database:install
php artisan migrate

Basic Usage

  1. Create a tenant migration in database/migrations/tenant/0001_create_projects_table.php.
  2. Use the UsesTenantConnection trait on your models:
use Illuminate\Database\Eloquent\Model;
use NexusScholar\LaravelTenantSqlite\Concerns\UsesTenantConnection;

class Project extends Model
{
    use UsesTenantConnection;
}
  1. Provision a tenant and run their migrations:
use NexusScholar\LaravelTenantSqlite\Facades\TenantDatabase;

$user = User::find(1);
TenantDatabase::provision($user);
TenantDatabase::migrate($user);
  1. Use the middleware to automatically route requests to the correct database:
// routes/web.php
Route::middleware(['auth', 'tenant'])->group(function () {
    Route::get('/projects', function () {
        // This automatically queries the authenticated user's SQLite file!
        return App\Models\Project::all();
    });
});

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.