Skip to content

Commit 42b9030

Browse files
authored
Add Livewire listener and register (#400)
1 parent 7505449 commit 42b9030

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/Concerns/ProvidesDefaultConfigurationOptions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static function prepareApplicationForNextOperation(): array
5151

5252
// First-Party Packages...
5353
\Laravel\Octane\Listeners\PrepareInertiaForNextOperation::class,
54+
\Laravel\Octane\Listeners\PrepareLivewireForNextOperation::class,
5455
\Laravel\Octane\Listeners\PrepareScoutForNextOperation::class,
5556
\Laravel\Octane\Listeners\PrepareSocialiteForNextOperation::class,
5657
];
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Laravel\Octane\Listeners;
4+
5+
use Livewire\LivewireManager;
6+
7+
class PrepareLivewireForNextOperation
8+
{
9+
/**
10+
* Handle the event.
11+
*
12+
* @param mixed $event
13+
* @return void
14+
*/
15+
public function handle($event): void
16+
{
17+
if (! $event->sandbox->resolved(LivewireManager::class)) {
18+
return;
19+
}
20+
21+
$manager = $event->sandbox->make(LivewireManager::class);
22+
23+
if (method_exists($manager, 'flushState')) {
24+
$manager->flushState();
25+
}
26+
}
27+
}

src/OctaneServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ protected function bindListeners()
130130
$this->app->singleton(Listeners\GiveNewRequestInstanceToApplication::class);
131131
$this->app->singleton(Listeners\GiveNewRequestInstanceToPaginator::class);
132132
$this->app->singleton(Listeners\PrepareInertiaForNextOperation::class);
133+
$this->app->singleton(Listeners\PrepareLivewireForNextOperation::class);
133134
$this->app->singleton(Listeners\PrepareScoutForNextOperation::class);
134135
$this->app->singleton(Listeners\PrepareSocialiteForNextOperation::class);
135136
$this->app->singleton(Listeners\ReportException::class);

0 commit comments

Comments
 (0)