Skip to content

Commit

Permalink
If route is livewire, set locale to snapshot value or null instead of…
Browse files Browse the repository at this point in the history
… livewire
  • Loading branch information
jyrkidn committed Oct 12, 2023
1 parent 7506647 commit b5e5d30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/Http/Middleware/SetLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ public function handle(Request $request, Closure $next)

$locale = $request->segment(1);

if ($request->headers->has('X-LIVEWIRE')) {
$snapshot = json_decode($request->json('components.0.snapshot', []), true);
if (is_livewire_route($request)) {
$snapshot = json_decode($request->json('components.0.snapshot', ''), true);

if (isset($snapshot['memo']['locale'])) {
$locale = $snapshot['memo']['locale'];
} else {
$locale = null;
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ function is_filament_livewire_route($request): bool
return false;
}

$isLivewire = (Str::startsWith($request->path(), 'livewire/') || $request->headers->has('X-LIVEWIRE'));

if ($isLivewire && $request->server('HTTP_REFERER')) {
if (is_livewire_route($request) && $request->server('HTTP_REFERER')) {
$referer = $request->server('HTTP_REFERER');
$isFilament = collect(Filament::getPanels())
->contains(fn (Panel $panel) => Str::startsWith($referer, $panel->getUrl()));
Expand All @@ -43,3 +41,10 @@ function is_filament_livewire_route($request): bool
return false;
}
}

if (! function_exists('is_livewire_route')) {
function is_livewire_route($request): bool
{
return (Str::startsWith($request->path(), 'livewire/') || $request->headers->has('X-LIVEWIRE'));
}
}

0 comments on commit b5e5d30

Please sign in to comment.