Zum Inhalt springen
← Zurück zu den Projekten

Filament Widget Configuration

Version: v3 v4 v5 · branch: 3.x

Filament Widget Configuration

#Filament Widget Configuration

Buy Me A Coffee

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads License

Configure Filament's widget polling interval and lazy-loading default once, globally, without editing every widget class by hand — while never touching a widget that already customizes either property itself.

#Why this plugin exists

Filament hardcodes a default polling interval on every polling-capable widget (protected ?string $pollingInterval = '5s';) with no built-in way to change that default across an entire application. A PR adding a global Widget::configureUsing() hook for this was closed by the Filament maintainer, danharrin, because baking a global configureUsing() callback into core would silently override any widget's own customized $pollingInterval, with no clean way to preserve precedence.

This plugin solves the same problem from outside core, as an opt-in third-party plugin, with a precedence rule that never overrides a widget that has customized the behavior itself — the exact guarantee the upstream PR couldn't offer.

In a large project, changing the default polling interval or lazy-loading behavior otherwise means opening every single widget class by hand. This plugin lets you set both once, in config or in AppServiceProvider, and every widget that hasn't customized its own behavior inherits the new default automatically.

#How the precedence rule works

Before overriding a property, the plugin checks — via ReflectionProperty::getDeclaringClass() — whether that property still comes from Filament's own base class/trait (Filament\Widgets\*, Filament\Support\*). If it does, it's safe to override. If a widget subclass has redeclared the property itself, its declaring class is that subclass, and the plugin leaves it untouched.

On Filament 5, $isLazy (CanBeLazy) is still a static property, so it's overridden once, at boot time, on Filament's base Widget class — every subclass that hasn't redeclared it inherits the new default for free. $pollingInterval (CanPoll), however, is a non-static instance property, so it can't be pre-set for an entire class hierarchy; instead, the plugin registers a Livewire ComponentHook that applies the resolved default to each widget instance individually, on mount/hydrate, using the same declaring-class check per instance.

#Compatibility

Branch Filament
1.x 3.x
2.x 4.x
3.x 5.x

#Installation

You can install the package via composer:

composer require jeffersongoncalves/filament-widget-configuration:"^3.0"

Optionally publish the config file:

php artisan vendor:publish --tag=filament-widget-configuration-config

#Usage

By default the plugin auto-applies on every request using config/filament-widget-configuration.php — no panel wiring required.

return [
    'polling_interval' => env('FILAMENT_WIDGET_CONFIGURATION_POLLING_INTERVAL', '5s'),
    'lazy' => env('FILAMENT_WIDGET_CONFIGURATION_LAZY', true),
];

Set polling_interval to null to disable polling by default across the app.

If you prefer to configure it in code, use WidgetConfigurationPlugin fluently — e.g. from AppServiceProvider::boot(), registered on your panel:

use JeffersonGoncalves\Filament\WidgetConfiguration\WidgetConfigurationPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugin(
            WidgetConfigurationPlugin::make()
                ->pollingInterval('30s')
                ->lazy(false)
        );
}

Fluent values always win over the config file. Either way, a widget that already sets its own $pollingInterval or $isLazy keeps its own value.

#Testing

composer test

#Changelog

Please see CHANGELOG for more information on what has changed recently.

#Contributing

Please see CONTRIBUTING for details.

#Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

#Credits

#License

The MIT License (MIT). Please see License File for more information.

Neue Version verfügbar.