This repository contains the code for a demonstration CRM application built with Laravel and the Sprout package for multi-tenancy. The demo shows how to implement a multi-tenant architecture where tenant data is isolated within a single database while maintaining a single codebase.
- Multi-tenant architecture using the Sprout Laravel package
- Subdomain-based tenant identification
- Data isolation within a single database
- Automatic tenant detection
- Scoped data access to prevent cross-tenant access
Follow these steps to set up the application locally:
- PHP 8.1+
- Composer
- Node.js & NPM
- SQLIte or any other Laravel-supported database
-
Clone the repository:
git clone git@github.com:stevepop/crm-with-sprout.git cd crm-with-sprout -
Copy the environment file:
cp .env.example .env
-
Update the
.envfile with your database credentials and the following settings:SESSION_DRIVER=file TENANTED_DOMAIN=your-local-domain -
Install PHP dependencies:
composer install
-
Install JavaScript dependencies:
npm install
-
Generate application key:
php artisan key:generate
-
Run migrations and seeders:
php artisan migrate --seed
-
Start the development server:
php artisan serve
-
In a separate terminal, compile assets:
npm run dev
You can access the demo using the following tenant subdomains:
tenant1.your-local-domain or tenant1.localhost
tenant2.your-local-domain or tenant2.localhost
For local development, you may need to update your hosts file to map these subdomains to your local IP.
The application uses Sprout middleware to resolve the current tenant based on the subdomain. While Sprout supports multiple resolution methods (subdomains, paths, headers, session, or cookies), this demo specifically uses the subdomain approach.
Once the tenant is identified, the application automatically scopes all database queries to the current tenant, ensuring data isolation between tenants.
The multi-tenant architecture is implemented using the Sprout Laravel package, which provides:
- Tenant resolution via subdomains
- Automatic query scoping for tenant data isolation
- Tenant-aware authentication
- Tenant-aware routes
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open-sourced software licensed under the MIT license.

