Livewire conflict
StrangerGithuber opened this issue · comments
Describe the bug
When using livewire component and starting writing in the input field then livewire component gives 404 error message. It feels like the lang path doesn't work with livewire or I am missing something.
To Reproduce
Normally just setup a livewire page with input tag and a model and let the component refresh itself and after appears in popup a 404 error message.
Expected behavior
After component update will not appearing 404 error message.
Versions (please complete the following information)
- PHP: 8.1.13
- Database: 5.7.24
- Laravel: 9.42.2
- Package: astrotomic/laravel-translatable 11.11
Additional context
Code part from livewire:
// Forward the query string for the ajax requests.
fetch(
`${window.livewire_app_url}/livewire/message/${payload.fingerprint.name}`,
{
method: 'POST',
body: JSON.stringify(payload),
// This enables "cookies".
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
'Accept': 'text/html, application/xhtml+xml',
'X-Livewire': true,
// set Custom Headers
...(this.headers),
// We'll set this explicitly to mitigate potential interference from ad-blockers/etc.
'Referer': window.location.href,
...(csrfToken && { 'X-CSRF-TOKEN': csrfToken }),
...(socketId && { 'X-Socket-ID': socketId })
},
}
)
.then(response => {
if (response.ok) {
response.text().then(response => {
if (this.isOutputFromDump(response)) {
this.onError(message)
this.showHtmlModal(response)
} else {
this.onMessage(message, JSON.parse(response))
}
})
} else {
if (this.onError(message, response.status, response) === false) return
if (response.status === 419) {
if (store.sessionHasExpired) return
store.sessionHasExpired = true
this.showExpiredMessage(response, message)
} else {
response.text().then(response => {
this.showHtmlModal(response)
})
}
}
})
.catch(() => {
this.onError(message)
})
Followed this tutorial: https://mydnic.be/post/how-to-build-an-efficient-and-seo-friendly-multilingual-architecture-for-your-laravel-application .
Stack Trace
The full stack trace of the thrown exception.
Alright nothing.
I changed the RouteServiceProvider.php boot function to this and now it works:
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
$locale = request()->segment(1) === 'livewire' ? 'en' : request()->segment(1);
Route::middleware('api')
->prefix('api')
->group(base_path('routes/api.php'));
Route::middleware('web')
->prefix($locale)
->namespace($this->namespace)
->group(base_path('routes/web.php'));
});
}