Skip to content

BhavikTrambadiya/Filament-with-Multi-Tenancy-Laravel

Repository files navigation

Multi-Tenant Admin Panel with Filament

A multi-tenant application built with Laravel, Filament, and Laravel Passport for API authentication.

Installation Steps

  1. Clone the repository
git clone <repository-url>
cd <project-folder>
  1. Install dependencies
composer install
npm install
  1. Copy .env file
cp .env.example .env
  1. Generate application key
php artisan key:generate
  1. 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
  1. Run migrations
php artisan migrate
  1. Install Passport
php artisan passport:install

Environment Configuration

Add these variables to your .env file:

SESSION_DRIVER=cookie
SESSION_DOMAIN=(add your domain here if not localhost)

Laravel Passport Setup

  1. Add Passport service provider in config/app.php:
'providers' => [
    Laravel\Passport\PassportServiceProvider::class,
],
  1. Add HasApiTokens trait to User model:
use Laravel\Passport\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens;
}

Project Structure

Admin Panel (Filament)

Location: app/Filament/Admin

  • Manages central administration
  • User management
  • Tenant management

Store Panel

Location: app/Filament/Store

  • Tenant-specific administration
  • Book management
  • Order processing

Middleware Configuration

Location: app/Http/Kernel.php

protected $middlewareGroups = [
    'web' => [
        \Stancl\Tenancy\Middleware\InitializeTenancyByDomain::class,
    ],
];

Key Features

  1. Multi-Tenancy
  • Domain-based tenant identification
  • Separate database per tenant
  • Automatic database creation for new tenants
  1. Admin Panel
  • User management
  • Tenant creation and management
  • System-wide settings
  1. Store Panel
  • Book management
  • Inventory tracking
  • Order processing
  1. API Authentication
  • Secure API endpoints using Laravel Passport
  • Token-based authentication
  • Tenant-specific data isolation
  1. Database Management
  • Automatic tenant database creation
  • Database connection switching
  • Query logging for debugging

Important Files

  • app/Providers/TenancyServiceProvider.php - Tenancy configuration
  • app/Models/Book.php - Book model with tenant connection
  • app/Http/Controllers/Api/AuthController.php - API authentication
  • app/Http/Controllers/Api/BookController.php - Book CRUD operations
  • config/tenancy.php - Tenancy configuration

Security

  • API routes are protected with Passport authentication
  • Tenant data is isolated in separate databases
  • Central domains are protected from unauthorized access

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published