一键导入
filament-refresh-sidebar-development
Build and work with the Filament Refresh Sidebar plugin, including automatic and manual sidebar navigation refresh.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Build and work with the Filament Refresh Sidebar plugin, including automatic and manual sidebar navigation refresh.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
| name | filament-refresh-sidebar-development |
| description | Build and work with the Filament Refresh Sidebar plugin, including automatic and manual sidebar navigation refresh. |
Use this skill when:
This plugin is minimal by design. It consists of:
RefreshSidebarPlugin - Filament plugin that registers a render hook for JavaScript injectionRefreshSidebarServiceProvider - Package service provider that registers viewsJeffersonGoncalves\Filament\RefreshSidebar
| Class | Path | Purpose |
|---|---|---|
RefreshSidebarPlugin | src/RefreshSidebarPlugin.php | Plugin class, registers script render hook |
RefreshSidebarServiceProvider | src/RefreshSidebarServiceProvider.php | Service provider, registers views |
composer require jeffersongoncalves/filament-refresh-sidebar
No config files are needed. Register the plugin in your PanelProvider:
use JeffersonGoncalves\Filament\RefreshSidebar\RefreshSidebarPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
RefreshSidebarPlugin::make(),
]);
}
The plugin registers a JavaScript snippet via PanelsRenderHook::SCRIPTS_AFTER:
namespace JeffersonGoncalves\Filament\RefreshSidebar;
use Filament\Contracts\Plugin;
use Filament\Panel;
use Filament\View\PanelsRenderHook;
use Illuminate\Contracts\View\View;
class RefreshSidebarPlugin implements Plugin
{
public static function make(): static
{
return app(static::class);
}
public function getId(): string
{
return 'filament-refresh-sidebar';
}
public function register(Panel $panel): void
{
$panel->renderHook(
PanelsRenderHook::SCRIPTS_AFTER,
fn (): View => view('filament-refresh-sidebar::scripts')
);
}
public function boot(Panel $panel): void {}
}
namespace JeffersonGoncalves\Filament\RefreshSidebar;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
class RefreshSidebarServiceProvider extends PackageServiceProvider
{
public function configurePackage(Package $package): void
{
$package->name('filament-refresh-sidebar')
->hasViews();
}
}
When Laravel Echo is configured, the plugin automatically listens for database notification events and triggers a sidebar refresh. This keeps navigation badges and menu items in sync without a full page reload.
Prerequisites:
Dispatch the refresh-sidebar event from any Livewire component:
// After creating a record
$this->dispatch('refresh-sidebar');
protected function afterCreate(): void
{
$this->dispatch('refresh-sidebar');
}
protected function afterDelete(): void
{
$this->dispatch('refresh-sidebar');
}
use Filament\Actions\Action;
Action::make('approve')
->action(function () {
// ... approval logic
$this->dispatch('refresh-sidebar');
}),
protected function afterSave(): void
{
$this->dispatch('refresh-sidebar');
}
Cause: Laravel Echo is not configured or broadcasting driver is missing.
Solution: Ensure Laravel Echo is installed (npm install laravel-echo), broadcasting is configured in .env, and the Echo connection is established in the browser.
Cause: The refresh-sidebar event is not being dispatched correctly.
Solution: Ensure you call $this->dispatch('refresh-sidebar') from within a Livewire component. The event name must match exactly.
Cause: The sidebar refresh triggers a re-render, but the badge count query may be cached.
Solution: Ensure your getNavigationBadge() method performs a fresh query and does not rely on cached values.
基于 SOC 职业分类