bezhanSalleh / filament-language-switch

A versatile and user-friendly plugin designed for Filament Panels.
MIT License
210 stars 45 forks source link

Update SwitchLanguageLocale.php #63

Closed stevefontaine closed 8 months ago

stevefontaine commented 9 months ago

When the middleware is added to the whole app and not only to Filament panels, livewire triggers request with JsonResponse. This PR intends to make it valid.

With this middleware added to Http\Kernel.php, the whole app can benefit from the language switcher when using panels inside subdomains ( admin.example.com and main site example.com )

bezhanSalleh commented 8 months ago

Unfortunately, the approach you've mentioned will not be effective. Filament operates with its own distinct middleware set, so adding anything to the kernel's global middleware stack is unlikely to yield the expected results(for this plugin anyways). Specifically, the plugin middleware should be strategically positioned immediately before the DispatchServingFilamentEvent middleware within the panel. This is seamlessly handled by the plugin itself, which automatically injects the middleware for the panels that are available. This automated process is the reason behind the absence of manual instructions in the documentation.

For experimental purposes, if you wish to explore this further, you may consider commenting out the $this->registerPluginMiddleware(); line within the packageBooted() method of the plugin's service provider. Then add the middleware to the global middlware stack and try switching the language.