LaravelPackages.net
Acme Inc.
Toggle sidebar
nexus-scholar/laravel-tenant-sqlite

Laravel package for isolated per-tenant SQLite databases

0
0
v1.0.0
About nexus-scholar/laravel-tenant-sqlite

nexus-scholar/laravel-tenant-sqlite is a Laravel package for laravel package for isolated per-tenant sqlite databases. It currently has 0 GitHub stars and 0 downloads on Packagist (latest version v1.0.0). Install it with composer require nexus-scholar/laravel-tenant-sqlite. Discover more Laravel packages by nexus-scholar or browse all Laravel packages to compare alternatives.

Last updated

Laravel Tenant SQLite

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.

Star History Chart