Installation:
composer require stephenjude/filament-jetstream
php artisan filament-jetstream:install [--teams] [--api]
--teams for team support, --api for API token management.Publish Migrations:
php artisan vendor:publish --tag=filament-jetstream-migrations
php artisan migrate
Configure User Model:
Update App\Models\User to include required traits:
use Filament\Jetstream\InteractsWithProfile;
use Laravel\Sanctum\HasApiTokens; // Only if using API
use Filament\Jetstream\InteractsWithTeams; // Only if using teams
Register Plugin:
In App\Providers\FilamentServiceProvider:
public function panel(Panel $panel): Panel
{
return $panel
->plugin(JetstreamPlugin::make());
}
JetstreamPlugin::make() configuration.Authentication & Registration:
Profile Management:
InteractsWithProfile trait to add custom profile fields:
public static function getFilamentProfileFields(): array
{
return [
TextInput::make('custom_field')->required(),
];
}
Teams (Optional):
InteractsWithTeams for multi-tenancy.Role model or gates/policies.API Tokens (Optional):
->apiTokens(permissions: fn() => ['create', 'read'])
Two-Factor Authentication (2FA):
->twoFactorAuthentication(condition: fn() => true)
Feature gates to conditionally enable/disable features (e.g., teams in staging).'filament-jetstream::profile/fields.name.label' => 'Custom Name',
php artisan vendor:publish --tag=filament-jetstream-routes
Migration Conflicts:
users table, ensure no column conflicts (e.g., profile_photo_path).Trait Overrides:
InteractsWithProfile/InteractsWithTeams unless necessary. Use Filament’s hooks or custom fields instead.public function getFilamentProfileWidgets(): array
{
return [
StatsOverviewWidget::make()->columns(2),
// Custom widgets here
];
}
API Token Scopes:
HasApiTokens:
public function getSanctumTokenableAttributes(): array
{
return ['*'];
}
Team Invitation Bugs:
acceptTeamInvitation callback in the plugin config to enforce logic:
->teams(acceptTeamInvitation: fn($invitationId) => JetstreamPlugin::make()->defaultAcceptTeamInvitation())
Filament Version Mismatches:
composer.json for constraints).filament/filament:^4.0 for stability..env:
FILAMENT_DEBUG=true
php artisan migrate:fresh --seed
JetstreamPlugin::make() (e.g., condition: fn() => auth()->check()).Custom Fields:
getFilament[Resource/Page]Fields() methods.Event Listeners:
UserRegistered) to trigger custom logic:
Event::listen(UserRegistered::class, function ($user) {
// Send welcome email
});
Views:
php artisan vendor:publish --tag=filament-jetstream-views
resources/views/vendor/filament-jetstream/....Testing:
$this->actingAs($user)
->get('/filament/admin/resources/users')
->assertSuccessful();
->profilePhoto(condition: fn() => false) // Hide profile photo upload
->deleteAccount(condition: fn() => false) // Disable account deletion
->twoFactorAuthentication(enablePasskey: fn() => true)
QueryBuilder.->updatePassword(condition: fn() => auth()->user()->isAdmin())
```markdown
### Config Quirks
1. **Feature Conditions**:
- Conditions (e.g., `condition: fn() => Feature::active('teams')`) are evaluated **per request**. Cache feature checks if performance is critical:
```php
->teams(condition: fn() => cache()->remember('teams_enabled', now()->addHours(1), fn() => Feature::active('teams')))
```
2. **Plugin Initialization**:
- The plugin **must** be registered in `FilamentServiceProvider` **before** the panel is returned. Order matters:
```php
public function panel(Panel $panel): Panel
{
return $panel
->id('admin')
->plugin(JetstreamPlugin::make()) // Register first
->navigationGroups([...]);
}
```
3. **Team Model Binding**:
- Ensure `Team` model uses `Filament\Models\Contracts\HasTenants` and implements `HasTenants`:
```php
class Team extends Model implements HasTenants
{
use InteractsWithTenants;
}
```
4. **API Token Permissions**:
- Permissions defined in `apiTokens(permissions: [...])` are **not** Sanctum scopes. Use Sanctum’s `HasApiTokens` for scope-based authorization.
5. **Translation Fallbacks**:
- Default translations are in `resources/lang/vendor/filament-jetstream`. Override them in your app’s `lang` directory:
```bash
php artisan vendor:publish --tag=filament-jetstream-translations
```
How can I help you explore Laravel packages today?