首页 > 解决方案 > "GET method is not supported for this route" even though it's a POST route

问题描述

I have a POST route in my Laravel application:

Route::post('/register-direct', 'Auth\RegisterController@direct')->name('register.direct');

Currently the method doesn't do anything but try to log the request:

public function direct(Request $request) {
    logger()->info($request->all());
}

Since this route should be accessible from outside the domain, I disabled CSRF protection for it:

class VerifyCsrfToken extends Middleware
{
    /**
     * Indicates whether the XSRF-TOKEN cookie should be set on the response.
     *
     * @var bool
     */
    protected $addHttpCookie = true;

    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'register-direct'
    ];
}

However, the strangest thing is happening. Even though it's a POST route, when I try to send the request from Postman to my remote site, I get the error:

The GET method is not supported for this route. Supported methods: POST.

From what I see, it is doing some sort of redirect to /register-direct as a GET route for some reason. The request never reaches the appropriate controller method (since the logging in the method never happens).

I suspect some middleware is the culprit, but the only middleware on this controller is the guest() middleware. And when I disable this middleware, it doesn't change anything.

Additional info:

标签: laravel

解决方案


推荐阅读