Inertia/Laravel PATCH redirect also tries to update the referrer
P粉265724930
P粉265724930 2023-09-04 11:56:57
0
1
598
<p>I have a Laravel/InertiaJS application where I perform Axios requests from a Vue frontend to update some models. In my case, I have a <strong>Proposal</strong> display page that also displays the <strong>Tasks</strong> related to the proposal. </p> <p>I have a Vue subcomponent that performs an Axios call to update a specific task: </p> <pre class="brush:php;toolbar:false;">const moveToNextStatus = (status) => { console.log('run') // update the status of the task using axios axios.patch(`/data/tasks/${props.task.id}`, { status: status }) }</pre> <p>This is the route it points to:</p> <pre class="brush:php;toolbar:false;">Route::patch('/data/tasks/{task}', [\App\Http\Controllers\TaskController::class, 'update'] )->name('tasks.update');</pre> <p>Then, in my Laravel <strong>TaskController</strong>, my update method looks like this: </p> <pre class="brush:php;toolbar:false;">public function update (Request $request, Task $task) { $task->update($request->all()); return redirect()->back(); }</pre> <p>For some reason, when Axios' request for PATCH /tasks/{task} fires, it also calls route <strong>PATCH /proposals/{proposal}</strong> and attempts to update the failed proposal. < /p> <p>Maybe this has something to do with redirecting from child components? Can anyone help me? </p>
P粉265724930
P粉265724930

reply all(1)
P粉593118425

The documentation for Inertia states;

You can find this in the documentation here: https://inertiajs.com/redirects

It also expects you to use a non-standard helper for redirection, such as;

return to_route('users.index');

I don't agree with it, but it is what it is - using 303 when the page doesn't redirect at all seems to violate the network status code standard.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template