laravel/nova-pennant
Manage Laravel Pennant feature flags in Laravel Nova. Add the PennantTool to a resource to view and toggle features per scope, control who can modify values with canRun(), require password confirmation, and support rich/class-based feature options.
Installation:
composer require laravel/nova-pennant
Publish the configuration (if needed):
php artisan vendor:publish --provider="Laravel\Nova\PennantTool\PennantToolServiceProvider"
Register the Tool:
Add PennantTool::make() to your Nova resource's fields() method (as shown in the README). No additional configuration is required for basic usage.
First Use Case:
Feature Flag Management:
Integration with Nova Resources:
User, Team, or custom resources) for centralized access.Settings resource for admin-only feature control:
public function fields(NovaRequest $request) {
return [
// ... other fields ...
PennantTool::make()->onlyOnDetail(),
];
}
Role-Based Access:
PennantTool::make()->onlyOnForms()->canSee(fn ($request) => $request->user()->isAdmin());
Bulk Operations:
Environment-Specific Flags:
.env overrides) and sync changes across environments via Nova.Customizing Feature Display:
Override the tool’s default behavior by extending the PennantTool class:
use Laravel\Nova\PennantTool\PennantTool as BasePennantTool;
class CustomPennantTool extends BasePennantTool {
public function fields(NovaRequest $request) {
return [
Text::make('Custom Field')->onlyOnForms(),
parent::fields($request),
];
}
}
Register the custom tool in your ToolServiceProvider.
Webhook Triggers: Use Pennant’s webhook events to notify external services (e.g., Slack, Datadog) when flags change:
// In EventServiceProvider
Pennant::onFeatureToggled(function ($feature, $isActive) {
// Dispatch notification
});
A/B Testing Integration: Combine with Nova’s metrics tools to track feature adoption:
Multi-Tenant Isolation:
Scope feature flags to tenants by extending Pennant’s Feature model:
// app/Models/Pennant/Feature.php
public function scopeForTenant($query, $tenantId) {
return $query->where('tenant_id', $tenantId);
}
Authorization Misconfigurations:
canSee() or Nova’s built-in gates:
PennantTool::make()->canSee(fn ($request) => $request->user()->can('manage-features'));
Caching Conflicts:
php artisan cache:clear
Or configure Pennant to bypass cache for critical flags:
Pennant::disableCacheFor(['critical-feature']);
Performance with Large Feature Sets:
PennantTool::make()->perPage(20);
Environment Sync Delays:
// config/pennant.php
'storage' => 'database',
Log Feature Changes: Enable Pennant’s logging to track who toggled what:
Pennant::enableLogging();
Check logs at storage/logs/laravel.log.
Verify Tool Registration:
User, Settings).PennantTool::make() class name.Test Feature Visibility:
php artisan nova:incognito
Database Schema Mismatches:
php artisan pennant:install
To reinstall the Pennant tables.Custom Storage Backends:
Extend Pennant’s FeatureRepository to support custom storage (e.g., S3, DynamoDB):
Pennant::extend('s3', function () {
return new S3FeatureRepository();
});
Dynamic Feature Groups: Organize flags into collapsible groups in Nova:
PennantTool::make()->groupFeaturesBy('category');
Audit Trails:
Add a pennant_audit table to track changes:
// In PennantToolServiceProvider
Pennant::auditEnabled(true);
Dark Mode Compatibility: Override the tool’s CSS to match Nova’s dark theme:
// resources/css/nova-pennant.css
.nova-pennant-tool.dark-mode { /* Custom styles */ }
How can I help you explore Laravel packages today?