Aug 3, 2024
0
Level 1
InertiaJS, Laravel, Double request fired with 409 HTTP Status, after to_route
Hey,
I run into this strange issue after updating a ressource from my frontend via any Inertia.put/post/delete request.
output in the browser's dev console:
Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.
The telescope output:
GET /users 200 181ms 6m ago
GET /users 409 163ms 6m ago <-- suspicious second request
PUT /users/update 303 192ms 6m ago
suspicious second request:
Response:
"Empty Response"
Headers:
"host": "127.0.0.1:8000",
"accept": "text/html, application/xhtml+xml",
"accept-language": "de,en-US;q=0.7,en;q=0.3",
"accept-encoding": "gzip, deflate, br, zstd",
"x-requested-with": "XMLHttpRequest",
"x-inertia": "true",
"x-xsrf-token": "********",
"referer": "http://127.0.0.1:8000/user",
"connection": "keep-alive",
"cookie": "********",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"priority": "u=0",
"pragma": "no-cache",
"cache-control": "no-cache"
Component.vue
Inertia.put(route('user.update'), form, {
onSuccess: () => {
closeDialog()
},
})
web.php
Route::get('/', [UsersController::class, 'index'])->name('user.index');
Route::put('/update', [UsersController::class, 'update'])->name('user.update');
UsersController.php
public function update(Request $request)
{
$user = User::find($request->id);
$sUserEmail = $request->Email;
$sUserPassword = $request->password;
$user->update ([
....
]);
return to_route('user.index'); <--- the redirect from the official inertia docs
}
public function index(): Response
{
$users = User::with('UserType')->get();
return Inertia::render('user/Index', [
'users' => $users ,
]);
}
How should I deal with it? Why does it happen? I read about Inertia forcing the frontend to update if versions don't match however that should happens once as far as I know.
Any ideas?
Please or to participate in this conversation.