Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

russellxu's avatar

Send a delete request and redirect back, 405 error

I send a delete request from Front end:

            this.$inertia.visit('/test/100', {
                method: 'delete',
                onSuccess: () => {
                    this.$notify.success('success')
                },
                onError: () => {
                    this.$notify.error('failed')
                },
            })

and at backend, I delete the data and redirect back:

    public function destroy($ids){
        $this->model->whereIn('id', explode(',', $ids))->delete();

        return redirect('/test');
    }

and an error occured, it says

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The DELETE method is not supported for this route. Supported methods: GET, HEAD, POST.
http://127.0.0.1:9998/test

aren't the request method of redirection supposed to be 'GET'? instead of 'DELETE'? How this work?

0 likes
19 replies
siangboon's avatar

do you have the correct Route::delete route for the request path declared in your web.php file??

russellxu's avatar

@siangboon function destory is executed,means I do have the right delete route, the problem is when I redirect, it redirect back to /test , using DELETE method instead of GET method.

Sinnbeck's avatar

@russellxu

Try this and see if you get the same error

public function destroy($ids){
        $this->model->whereIn('id', explode(',', $ids))->delete();

       dd('hit');
        return redirect('/test');
    } 
russellxu's avatar

@Sinnbeck I've tried, it's do get triggered, I know it because the corresponding record has been deleted.

Sinnbeck's avatar

What if you tell it to go back?

return redirect()->back(); 
Sinnbeck's avatar

@russellxu what if you use the delete method?

this.$inertia.delete('/test/100', {
                
                onSuccess: () => {
                    this.$notify.success('success')
                },
                onError: () => {
                    this.$notify.error('failed')
                },
            }) 
russellxu's avatar

@Sinnbeck redirect()->back() willl work, but the url isn't right, it redirect back to /test/124 instead of /test

Sinnbeck's avatar

@russellxu that's really weird. So you can redirect to any route except /test or?

Any chance that you have something on the /test page that does a request on mount?

russellxu's avatar

@Sinnbeck It is werid, here is my web.php file. only two rules

Route::post('/upload/image', 'App\Http\Controllers\UploadController@image');
Route::resource('/test', 'App\Http\Controllers\TestController');

I change redirect('/test') to Redirect::route('test.index'), still get the same error.

Sinnbeck's avatar

@russellxu any chance you can make a test repo with the bug and put it on github? If there indeed is a bug, I'm sure Jonathan would love to know

russellxu's avatar

@Sinnbeck I've just changed route of destroy method from delete to post.

Route::get('/test', 'App\Http\Controllers\TestController@index')->name('test.index');
Route::post('/test/{id}', 'App\Http\Controllers\TestController@destroy');

and sent post request

            this.$inertia.post('/test/100', {
                // method: 'delete',
                onSuccess: () => {
                    this.$notify.success('success')
                },
                onError: () => {
                    this.$notify.error('failed')
                },
            })

and it worked, no errors!

Sinnbeck's avatar

@russellxu It still seems weird. I use inertia daily and have tons of routes that does exactly what you are doing, and they all work as expected :/

russellxu's avatar

@Sinnbeck Have you try what i'm trying? Send a delete request from index page and redirect back to index page

Sinnbeck's avatar

@russellxu Yeah. It works perfectly for me. I just tried it out. I use react instead of vue, but as I understand, your problem is that laravel somehow redirects with a DELETE (which shouldnt be possible as you cannot set the method of a redirect)

If you can make a repo on github with the error, I would be happy to investigate further.

russellxu's avatar

@Sinnbeck It works! I forgot to add the middleware. But, seriously, inertiaJs should throw an error or warning on frontend, and I should read core code when I got time. :)

Please or to participate in this conversation.