Inertia/Laravel PATCH redirect also tries to update the referrer
P粉265724930
P粉265724930 2023-09-04 11:56:57
0
1
484

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 Proposal display page that also displays the Tasks related to the proposal.

I have a Vue subcomponent that performs an Axios call to update a specific task:

const moveToNextStatus = (status) => { console.log('run') // update the status of the task using axios axios.patch(`/data/tasks/${props.task.id}`, { status: status }) }

This is the route it points to:

Route::patch('/data/tasks/{task}', [\App\Http\Controllers\TaskController::class, 'update'] )->name('tasks.update');

Then, in my Laravel TaskController, my update method looks like this:

public function update (Request $request, Task $task) { $task->update($request->all()); return redirect()->back(); }

For some reason, when Axios' request for PATCH /tasks/{task} fires, it also calls route PATCH /proposals/{proposal} and attempts to update the failed proposal. < /p>

Maybe this has something to do with redirecting from child components? Can anyone help me?

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
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!