laravel-localization: Route Trans Caching is broken with Livewire 3
Describe the bug
When using Livewire 3, it is not possible to cache the localized routes with php artisan route:trans:cache
.
Livewire 2 automatically preserved the URL prefix when making component updates via https://example.com/en/livewire/update
Livewire 3 has stopped supporting this behavior automatically.
See official Livewire documentation mentioning Laravel Localization: https://livewire.laravel.com/docs/upgrading#localization
To Reproduce Steps to reproduce the behavior:
- Require Livewire 3 and update the Livewire update route (as recommended in the official Livewire documentation)
- Cache localized routes using:
php artisan route:trans:cache
- Browse your website using a Laravel Localization locale (EN in my example)
- Open the browser console and click on a Livewire button (or any Livewire action)
- Console logs a call to
/livewire/update instead
of/en/livewire/update
and returns a 404
Expected behavior
When browing the FR locale (or any other locales), you would expect Livewire to call /en/livewire/update
instead of the non-localized route /livewire/update
This only fails when php artisan route:trans:cache
has been run previously.
If you run php artisan route:trans:clear
, it works correctly.
So something is broken in caching the route.
More info:
- Version of Laravel: 10
- Version of the Laravel-localization package: 1.8
- Which middleware is used in
Route::groups
: setLocale
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 7
- Comments: 17 (2 by maintainers)
Maybe I found a solution inspired by this file.
Remove this block from the
web.php
…… and put it in the
RouteServiceProvider.php
. Don’t forget themiddleware()
andprefix()
method.Now
Livewire::setUpdateRoute
will not be cached if you runphp artisan route:trans:cache
.Same here. Cache is broken.
I does work without caching while adding the new
setUpdateRoute
method to the route group.Awesome, this works perfectly!
Whatever the culprit is both Livewire 3 and LaravelLocalization are quite popular packages. But I’d say it’s easier to fix LaravelLocalization. Or at least put the info in the docs how fix it for now.
I am having this issue without the route:trans:cache. I can clear it and still get the error. It is posting to /livewire/update instead of /en/livewire/update
genius, thankyou it saves to put the hands in livewire.
the getRoutes function was failing to find the route in livewire even if i put livewire/update in the ignore list.
your solution is simple and elegant (after you know how 😃
Thank you so much! You saved my day!
The workaround is on the top of this thread.
Route::group([‘prefix’ => LaravelLocalization::setLocale()], function () { // Your other localized routes…
});
What is needed is a permanent solution and a bit of attention by the package owner.
https://github.com/mcamara/laravel-localization/issues/880#issuecomment-1703773314