marjose123/filament-no-connection
Installation:
composer require marjose123/filament-no-connection
Run this in your Laravel project to add the package.
Service Provider Registration:
The package auto-discovery will handle this, but ensure FilamentNoConnectionServiceProvider is registered in config/app.php under providers if not using auto-discovery.
First Use Case:
config/filament-no-connection.php (published via php artisan vendor:publish --tag="filament-no-connection-config").resources/views/vendor/filament-no-connection/. Customize these if you need to alter the alert appearance.FilamentNoConnectionServiceProvider to understand how connection checks are hooked into Filament’s lifecycle.Basic Integration:
// In a Filament resource or page, trigger a manual check (if needed):
use MarJose123\FilamentNoConnection\Facades\FilamentNoConnection;
public function mount()
{
FilamentNoConnection::checkConnections(); // Force a check (optional)
}
Custom Connection Checks:
ConnectionChecker class or bind a custom checker in the service provider:
$this->app->bind(
\MarJose123\FilamentNoConnection\Contracts\ConnectionChecker::class,
\App\Services\CustomConnectionChecker::class
);
Alert Customization:
resources/views/vendor/filament-no-connection/alert.blade.php to change the alert message, styling, or behavior.FilamentNoConnection::setAlertData(['error' => 'Custom error message']);
Conditional Alerts:
ignored_routes or ignored_panels in the config file:
'ignored_routes' => [
'filament/admin/pages/dashboard',
],
Debugging Connection Issues:
// In AppServiceProvider's boot method:
FilamentNoConnection::setLogger(\Log::channel('single'));
Graceful Degradation:
try-catch blocks to handle failures gracefully. Example:
try {
DB::connection()->getPdo();
} catch (\Exception $e) {
FilamentNoConnection::triggerAlert('Database unavailable');
}
Testing:
$this->partialMock(DB::class, 'connection')->shouldReceive('getPdo')->andThrow(new \Exception('Test failure'));
$this->get('/filament/admin')->assertSee('No connection');
php artisan vendor:publish --tag="filament-no-connection-lang"
False Positives:
config/filament-no-connection.php to adjust sensitivity:
'retries' => 3, // Number of retries before showing an alert
'retry_delay' => 5, // Delay in seconds between retries
Ignored Routes Misconfiguration:
ignored_routes and ignored_panels arrays in the config.Overriding Views Incorrectly:
php artisan view:clear
Database Connection Checks:
ConnectionChecker as shown in the Implementation Patterns section.Filament Version Compatibility:
composer.json for supported versions.Log Connection Checks:
'debug' => env('APP_DEBUG', false),
storage/logs/laravel.log for detailed connection check results.Manual Alert Triggering:
FilamentNoConnection::triggerAlert('Test alert', 'error');
Check for Conflicts:
Custom Alert Icons:
<x-filament::icon icon="heroicon-o-exclamation-circle" class="mr-2" />
Alert Dismissal:
if (session()->has('dismissed_alerts')) {
$dismissed = session('dismissed_alerts');
}
Multi-Tenant Environments:
ConnectionChecker to include tenant-specific logic.Performance Monitoring:
Telescope::monitor(\MarJose123\FilamentNoConnection\Events\ConnectionCheckFailed::class);
Extending for APIs:
ConnectionCheckFailed:
\MarJose123\FilamentNoConnection\Events\ConnectionCheckFailed::class => function () {
// Send a webhook or broadcast the event
},
How can I help you explore Laravel packages today?