A multi-tenant application built with Laravel, Filament, and Laravel Passport for API authentication.
- Clone the repository
git clone <repository-url>
cd <project-folder>
- Install dependencies
composer install
npm install
- Copy .env file
cp .env.example .env
- Generate application key
php artisan key:generate
- Configure database settings in .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password
- Run migrations
php artisan migrate
- Install Passport
php artisan passport:install
Add these variables to your .env file:
SESSION_DRIVER=cookie
SESSION_DOMAIN=(add your domain here if not localhost)
- Add Passport service provider in
config/app.php
:
'providers' => [
Laravel\Passport\PassportServiceProvider::class,
],
- Add HasApiTokens trait to User model:
use Laravel\Passport\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens;
}
Location: app/Filament/Admin
- Manages central administration
- User management
- Tenant management
Location: app/Filament/Store
- Tenant-specific administration
- Book management
- Order processing
Location: app/Http/Kernel.php
protected $middlewareGroups = [
'web' => [
\Stancl\Tenancy\Middleware\InitializeTenancyByDomain::class,
],
];
- Multi-Tenancy
- Domain-based tenant identification
- Separate database per tenant
- Automatic database creation for new tenants
- Admin Panel
- User management
- Tenant creation and management
- System-wide settings
- Store Panel
- Book management
- Inventory tracking
- Order processing
- API Authentication
- Secure API endpoints using Laravel Passport
- Token-based authentication
- Tenant-specific data isolation
- Database Management
- Automatic tenant database creation
- Database connection switching
- Query logging for debugging
app/Providers/TenancyServiceProvider.php
- Tenancy configurationapp/Models/Book.php
- Book model with tenant connectionapp/Http/Controllers/Api/AuthController.php
- API authenticationapp/Http/Controllers/Api/BookController.php
- Book CRUD operationsconfig/tenancy.php
- Tenancy configuration
- API routes are protected with Passport authentication
- Tenant data is isolated in separate databases
- Central domains are protected from unauthorized access