shuvroroy/filament-spatie-laravel-health
Install the package:
composer require shuvroroy/filament-spatie-laravel-health
Publish migrations (if using Eloquent storage):
php artisan vendor:publish --tag="health-migrations"
php artisan migrate
Register the plugin in AdminPanelProvider:
public function panel(Panel $panel): Panel {
return $panel
->plugin(FilamentSpatieLaravelHealthPlugin::make());
}
Define health checks in AppServiceProvider:
public function boot(): void {
Health::checks([
OptimizedAppCheck::new(),
DebugModeCheck::new(),
EnvironmentCheck::new(),
]);
}
Run Filament assets:
php artisan filament:assets
Access the Health Check Results page in Filament to monitor:
Register Checks:
Use Spatie’s built-in checks (e.g., DatabaseCheck, CacheCheck) or create custom ones.
Health::checks([
DatabaseCheck::new()
->expectTablesToExist(['users', 'posts'])
->expectTablesToBeReadable(['users']),
CustomCheck::new()->run(function () {
return Cache::get('critical_key') !== null;
}),
]);
Customize the Filament Page: Extend the default page for branding/navigation:
class CustomHealthPage extends BaseHealthCheckResults {
protected static ?string $navigationIcon = 'heroicon-o-heart';
public function getHeading(): string {
return 'System Vitality';
}
}
Register it in AdminPanelProvider:
->plugin(FilamentSpatieLaravelHealthPlugin::make()
->usingPage(CustomHealthPage::class)
)
Access Control:
Restrict access via the authorize method:
->plugin(FilamentSpatieLaravelHealthPlugin::make()
->authorize(fn () => auth()->user()->isAdmin())
)
schedule to run checks periodically:
$schedule->command('health:check')->daily();
Health::checks() and adding webhook logic.Health::store() before registering checks.Migration Conflicts:
health_check_result_history_items table exists. Run php artisan migrate after publishing migrations.php artisan vendor:publish --tag="health-migrations" --force
Check Registration Timing:
AppServiceProvider@boot or a dedicated service provider.Health::checks([])->assertRegistered() to verify checks are loaded.Filament Asset Caching:
php artisan filament:assets
php artisan cache:clear
Permission Denied:
authorize callback or Filament’s user permissions.Check Logs: Enable Spatie’s debug mode:
Health::debug();
Logs will appear in storage/logs/laravel.log.
Manual Check Execution: Run checks manually via Tinker:
php artisan tinker
>>> \Spatie\Health\Facades\Health::performChecks();
Custom Check Status Icons:
Override the getStatusIcon method in your extended page class:
public function getStatusIcon(string $status): string {
return match ($status) {
'passed' => 'heroicon-o-check-circle',
'failed' => 'heroicon-o-x-circle',
default => 'heroicon-o-minus-circle',
};
}
Dynamic Check Groups:
Use getNavigationGroup to categorize checks dynamically:
public static function getNavigationGroup(): ?string {
return request()->user()?->isSuperAdmin() ? 'Admin' : 'User';
}
Localization: Publish translations:
php artisan vendor:publish --tag="filament-spatie-laravel-health-translations"
Then customize resources/lang/vendor/filament-spatie-laravel-health/health.php.
Health::checks() if they’re irrelevant (e.g., DebugModeCheck in production).Health::store(NullHealthResultStore::class) to avoid database bloat.How can I help you explore Laravel packages today?