mvenghaus/filament-plugin-schedule-monitor
Install Dependencies Run these commands in sequence:
composer require spatie/laravel-schedule-monitor
php artisan vendor:publish --provider="Spatie\ScheduleMonitor\ScheduleMonitorServiceProvider" --tag="schedule-monitor-migrations"
php artisan migrate
composer require mvenghaus/filament-plugin-schedule-monitor:"^3.0"
Register the Plugin
Add the plugin to your AdminPanelProvider (e.g., app/Providers/Filament/AdminPanelProvider.php):
public function panel(Panel $panel): Panel
{
return $panel
->plugin(\Mvenghaus\FilamentScheduleMonitor\FilamentPlugin::make());
}
First Use Case Visit your Filament admin panel. The plugin adds a "Schedule Monitor" widget to the dashboard by default, showing:
Dashboard Integration
FilamentPlugin::make()
->widgets([
\Mvenghaus\FilamentScheduleMonitor\Widgets\ScheduleMonitorWidget::class,
])
->sort(10); // Adjust priority
Resource Integration (Optional)
use Mvenghaus\FilamentScheduleMonitor\Resources\ScheduleMonitorResource;
FilamentPlugin::make()
->resources([
ScheduleMonitorResource::class,
]);
Resources > Schedule Monitor in the Filament sidebar.Customizing Data Display
class CustomScheduleMonitorWidget extends ScheduleMonitorWidget
{
protected function getTableQuery(): Builder
{
return parent::getTableQuery()->where('command', 'like', '%backup%');
}
}
FilamentPlugin::make()
->widgets([
CustomScheduleMonitorWidget::class,
]);
Conditional Visibility
FilamentPlugin::make()
->widgets([
ScheduleMonitorWidget::class,
])
->visible(fn (User $user) => $user->isAdmin());
Leverage Spatie’s Features
The plugin surfaces Spatie’s laravel-schedule-monitor data. Use Spatie’s documentation to:
schedule:run in app/Console/Kernel.php.Combine with Filament Actions Add buttons to trigger commands manually from the resource:
ScheduleMonitorResource::class,
use Filament\Resources\Actions\Action;
public static function getActions(): array
{
return [
Action::make('Run Now')
->url(fn ($record) => route('schedule.run', $record->command))
->openUrlInNewTab(),
];
}
Notifications for Failures Extend the plugin to send alerts (e.g., Slack, Email) when jobs fail:
// In a Service Provider
ScheduleMonitor::failed(function (FailedJob $failedJob) {
Notification::route('mail', 'admin@example.com')
->notify(new ScheduleFailed($failedJob));
});
Missing Migrations
php artisan migrate after installing spatie/laravel-schedule-monitor will break the plugin. Always run:
php artisan migrate
Caching Issues
php artisan filament:cache-reset
Permission Denied
schedule_monitor tables. Ensure your Filament user has database permissions.Command Not Logging
app/Console/Kernel.php under $schedule.schedule:run command is executed (e.g., via cron or manually).Check Logs Enable debug mode for Spatie’s monitor:
// config/schedule-monitor.php
'debug' => env('SCHEDULE_MONITOR_DEBUG', false),
Logs appear in storage/logs/laravel.log.
Verify Database Records
Inspect the schedule_monitor_runs table directly:
SELECT * FROM schedule_monitor_runs ORDER BY created_at DESC LIMIT 10;
Test Locally Manually trigger a scheduled command to populate data:
php artisan schedule:run
Custom Styling
Override the widget’s Blade view (resources/views/widgets/schedule-monitor.blade.php) or use Filament’s CSS variables:
.filament-schedule-monitor {
--fail-color: #ef4444;
--success-color: #10b981;
}
Performance For large schedules, paginate the resource:
ScheduleMonitorResource::class,
use Filament\Resources\Table;
public static function getTable(): Table
{
return Table::make(...)
->paginate(20);
}
Environment-Specific Config Disable the plugin in non-production environments:
FilamentPlugin::make()
->visible(fn () => app()->environment('production')),
Extend Functionality Add custom columns to the resource table:
Table::make(...)
->columns([
TextColumn::make('command')
->searchable(),
TextColumn::make('duration')
->formatStateUsing(fn ($state) => $state ? round($state, 2) . 's' : 'N/A'),
// Add more columns as needed
]),
Localization Translate widget labels by publishing the language file:
php artisan vendor:publish --tag="filament-schedule-monitor-lang"
Then edit resources/lang/en/filament-schedule-monitor.php.
How can I help you explore Laravel packages today?