composer require a2insights/filament-saas
php artisan vendor:publish --tag="filament-saas-migrations"
php artisan vendor:publish --tag="filament-saas-config"
php artisan vendor:publish --tag="filament-saas-views"
php artisan migrate
app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->registration()
->passwordReset()
->emailVerification()
->tenancy(); // Enable multi-tenancy
}
/admin to manage tenants, users, and features.Multi-Tenancy Management
FilamentSaas\Tenants\TenantsTable to list and manage tenants.FilamentSaas\Tenants\CreateTenant form.app/Providers/FilamentSaasServiceProvider.php:
public function boot(): void
{
Tenant::created(function (Tenant $tenant) {
// Custom logic on tenant creation
});
}
Feature Flags
FilamentSaas\Features\FeaturesTable.use FilamentSaas\Features\Feature;
Feature::toggle('analytics', true, $tenant);
Subscription Management
FilamentSaas\Subscriptions\SubscriptionsTable.app/Models/Subscription.php:
public function handleWebhook($event, $payload)
{
// Custom webhook handling
}
Customizing Views
resources/views/vendor/filament-saas/.@extends('filament-saas::tenants.dashboard')
@section('content')
{{-- Custom content --}}
@endsection
public function getWidgets(): array
{
return [
StatsOverview::class,
RecentTenants::class,
// Custom widget
CustomWidget::class,
];
}
routes/api.php:
Route::middleware('auth:sanctum')->group(function () {
Route::apiResource('tenants', TenantController::class);
Route::post('tenants/{tenant}/features', [FeatureController::class, 'toggle']);
});
Namespace Conflicts
App\Models\Tenant vs. FilamentSaas\Models\Tenant).config/filament-saas.php:
'models' => [
'tenant' => App\Models\Tenant::class,
],
Migration Issues
tenants vs. filament_tenants).database/migrations/ or use --force with caution.Tenancy Scope Misconfiguration
// Wrong: Leaks data across tenants
Tenant::all();
// Correct: Scoped to current tenant
Tenant::forCurrentTenant()->get();
Feature Flag Caching
php artisan cache:clear
config(['filament-saas.debug' => true]);
TenantMiddleware is registered in app/Http/Kernel.php:
protected $middlewareGroups = [
'web' => [
// ...
\FilamentSaas\Http\Middleware\TenantMiddleware::class,
],
];
Custom Tenant Fields
Tenant model and update the form:
use FilamentSaas\Forms\Components\TenantFields;
TenantFields::make()
->schema([
// Default fields
TenantFields::make()->schema(),
// Custom field
TextInput::make('custom_field')->required(),
]);
Webhook Handlers
public function handleWebhook($event, $payload)
{
if ($event === 'invoice.payment_succeeded') {
// Custom logic (e.g., grant features)
Feature::toggle('premium', true, $this->tenant);
}
}
Localization
php artisan vendor:publish --tag="filament-saas-translations"
resources/lang/en/filament-saas.php for translations.Testing
TenancyTestingTrait for tenant-aware tests:
use FilamentSaas\Testing\TenancyTestingTrait;
class TenantTest extends TestCase
{
use TenancyTestingTrait;
public function test_tenant_creation()
{
$this->actingAsAdmin();
$this->createTenant(['name' => 'Test Tenant']);
$this->assertDatabaseHas('tenants', ['name' => 'Test Tenant']);
}
}
How can I help you explore Laravel packages today?