shuvroroy/filament-spatie-laravel-health
Install Dependencies
Run composer require shuvroroy/filament-spatie-laravel-health spatie/laravel-health to install both packages.
Ensure filament/filament is also installed (composer require filament/filament).
Publish Config Publish the package config with:
php artisan vendor:publish --provider="ShuvroRoy\FilamentSpatieLaravelHealth\FilamentSpatieLaravelHealthServiceProvider" --tag="config"
This generates config/filament-spatie-laravel-health.php.
Register Checks
Define health checks in config/health.php (from spatie/laravel-health). Example:
'checks' => [
\Spatie\Health\Checks\Checks\DatabaseConnection::new(),
\Spatie\Health\Checks\Checks\CacheConnection::new(),
],
Access the Page The health dashboard will appear under Resources > Health in your Filament admin panel.
Define Checks
Extend spatie/laravel-health checks in config/health.php:
'checks' => [
\App\Health\Checks\CustomCheck::new(), // Custom class
\Spatie\Health\Checks\Checks\Storage::new(), // Built-in check
],
Example custom check:
namespace App\Health\Checks;
use Spatie\Health\Checks\Check;
class CustomCheck extends Check {
public function run(): array {
return [
'status' => 'ok',
'message' => 'Custom logic passed',
];
}
}
Group Checks
Use the group() method in config to organize checks:
'checks' => [
\Spatie\Health\Checks\Checks\DatabaseConnection::new()->group('Database'),
\Spatie\Health\Checks\Checks\CacheConnection::new()->group('Cache'),
],
Conditional Checks Skip checks based on environment:
'checks' => [
app()->environment('local') ? \Spatie\Health\Checks\Checks\Queue::new() : null,
],
Filament Widgets Embed health status as a widget in your Filament dashboard:
use ShuvroRoy\FilamentSpatieLaravelHealth\Widgets\HealthStatusWidget;
public function getWidgets(): array {
return [
HealthStatusWidget::class,
];
}
Scheduled Runs Use Laravel’s scheduler to run checks periodically:
// app/Console/Kernel.php
protected function schedule(Schedule $schedule) {
$schedule->command('health:run')->hourly();
}
API Access
Expose health checks via API using spatie/laravel-health's HealthCheckRunner:
use Spatie\Health\HealthCheckRunner;
Route::get('/api/health', function () {
return HealthCheckRunner::run();
});
Missing Dependencies
spatie/laravel-health is installed. The package won’t work without it.filament/filament is installed (v2+ recommended).Permission Issues
config/filament.php:
'pages' => [
'health' => [
'permission' => 'view-health',
],
],
Check Failures in Development
QueueConnection) may fail in local environments. Exclude them:
app()->environment('local') ? null : \Spatie\Health\Checks\Checks\Queue::new(),
Caching Side Effects
php artisan cache:clear
php artisan view:clear
Check Logs
Enable debug mode in config/filament-spatie-laravel-health.php:
'debug' => env('APP_DEBUG', false),
Logs will appear in storage/logs/laravel.log.
Manual Check Execution Run checks via CLI for debugging:
php artisan health:run
Verify Config
Ensure config/health.php is properly loaded. Test with:
php artisan health:list
Customize UI Override the Filament page by publishing views:
php artisan vendor:publish --provider="ShuvroRoy\FilamentSpatieLaravelHealth\FilamentSpatieLaravelHealthServiceProvider" --tag="views"
Modify resources/views/vendor/filament-spatie-laravel-health/....
Add Check Metadata Extend checks with custom metadata (e.g., severity, description):
\Spatie\Health\Checks\Checks\DatabaseConnection::new()
->description('Verifies MySQL connection')
->severity('high'),
Hook into Check Results
Listen for check events in EventServiceProvider:
protected $listen = [
\Spatie\Health\Events\CheckWasRun::class => [
\App\Listeners\LogHealthCheck::class,
],
];
Localization Translate check messages by publishing lang files:
php artisan vendor:publish --provider="ShuvroRoy\FilamentSpatieLaravelHealth\FilamentSpatieLaravelHealthServiceProvider" --tag="lang"
Override in resources/lang/{locale}/health.php.
How can I help you explore Laravel packages today?