Install Laravel
composer create-project laravel/laravel backend
composer require filament/filament:"^5.0"
php artisan filament:install --panels
Install Filament Shield
composer require bezhansalleh/filament-shield
php artisan vendor:publish --tag="filament-shield-config"
Set Filament Shield config file /config/filament-shield.php
'auth_provider_model' => 'App\\Models\\User',
Set user model app/Models/User.php
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticable
{
use HasRoles;
}
Run setup
php artisan shield:setup
# multi-tenancy
php artisan shield:setup --tenant=App\\Models\\Team
Install Shield to Filament panel
php artisan shield:install admin --tenant --generate-relationships
# Replace 'admin' with your panel ID
Command steps
Team is my tenant table, you could name it Organization, Tenant, etc.
composer require bezhansalleh/filament-shield
php artisan vendor:publish --tag="filament-shield-config"
php artisan shield:setup --tenant=App\\Models\\Team --force
php artisan shield:install --tenant
php artisan shield:super-admin --tenant=1
php artisan shield:generate --all --option=policies --relationships
php artisan shield:seeder
php artisan db:seed --class=ShieldSeeder
php artisan migrate --seed
php artisan shield:super-admin --user=1 --panel=board --tenant=App\\Models\\Team
php artisan make:filament-resource User
php artisan shield:generate --resource=UserResource --option=policies --relationships
Don't forget to add tenant ownership relationship name on every filament resources.
<?php
use ...
class ....Resource extends Resource
{
...
protected static ?string $tenantOwnershipRelationshipName = "teams";
...
}
To exclude Tenant in certain resource add $isScopedToTenant = false.
<?php
...
...
class HelpdeskResource extends Resource
{
protected static bool $isScopedToTenant = false;
Generate
1. Generate Resource
Use the --generate flag when creating a resource to automatically create form fields and table columns based on your database schema, including simple relationship fields if doctrine/dbal is installed.
composer require doctrine/dbal --dev
php artisan make:filament-resource {resource-name} --model-namespace="App\\Models\\{vendor-name}\\{model-name}" --generate
# example
php artisan make:filament-resource Peraturan --model-namespace="App\\Models\\Agussudarmanto\\Peraturan" --generate
2. Generate Relation Manager
php artisan make:filament-relation-manager CategoryResource posts title
CategoryResource is the name of the parent resource class.
posts is the name of the relationship method in your Category model.
title is the attribute used to identify related records in the manager's table.
This command generates a new class in App\Filament\Resources\CategoryResource\RelationManagers\PostsRelationManager.php.
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Grid;
-- to
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Grid;
Top comments (0)