Skip to content

Commit 0a1fe06

Browse files
committed
Fix component registration for livewire v4
1 parent 44fe41f commit 0a1fe06

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

src/FilamentClearCachePlugin.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Filament\Panel;
88
use Illuminate\Support\Facades\Blade;
99
use Livewire\Livewire;
10+
use Composer\InstalledVersions;
11+
1012

1113
class FilamentClearCachePlugin implements Plugin
1214
{
@@ -28,19 +30,35 @@ public function getId(): string
2830

2931
public function register(Panel $panel): void
3032
{
31-
Livewire::component(
32-
'filament-clear-cache::clear-cache-button',
33-
config('filament-clear-cache.livewireComponentClass', ClearCache::class)
34-
);
33+
$component = config('filament-clear-cache.livewireComponentClass', ClearCache::class);
34+
35+
if (self::isLivewireV3()) {
36+
Livewire::component('filament-clear-cache::clear-cache-button', $component);
37+
}
3538

3639
$panel->renderHook(
3740
name: 'panels::user-menu.before',
38-
hook: fn (): string => Blade::render('@livewire(\'filament-clear-cache::clear-cache-button\')'),
41+
hook: fn (): string => Blade::render(
42+
'@livewire($component)'
43+
,['component' => $component]
44+
),
3945
);
4046
}
4147

4248
public function boot(Panel $panel): void
4349
{
44-
//
50+
if (! self::isLivewireV3()) {
51+
Livewire::addNamespace(
52+
namespace: 'filament-clear-cache',
53+
viewPath: __DIR__ . '/../resources/views/livewire',
54+
);
55+
}
56+
}
57+
58+
private static function isLivewireV3(): bool
59+
{
60+
$version = InstalledVersions::getVersion('livewire/livewire');
61+
62+
return version_compare($version, '4.0.0', '<');
4563
}
4664
}

0 commit comments

Comments
 (0)