没有 CSRF 的 MethodNotAllowedHttpException 路径

MethodNotAllowedHttpException path without CSRF

我在 laravel 中传递了一个由 JS 中的函数调用的路由,我无法控制它,因为它是外部的,这个路由是一个 post 方法,因为我需要它就是那样,但它会生成一个 MethodNotAllowedHttpException 就像我排除此验证的某些路径一样。

注意: 我已经尝试将它添加到 VerifyCsrfToken 的异常向量中,修改 class 文件 VerifyCsrfToken 将中间件扩展到一个名为的新文件class VerifyCsrfToken extends BaseVerifier 及其所有依赖项,我还禁用了中间件中的验证,但其中 none 对我有效

来自the docs

You should place these kinds of routes outside of the web middleware group that the RouteServiceProvider applies to all routes in the routes/web.php file. However, you may also exclude the routes by adding their URIs to the $except property of the VerifyCsrfToken middleware:

protected $except = [
    'your/route/*',
];

为此,您必须在 protected $except 中添加路由的 URI。 例如,如果您 URL 是 www.example.com/full/route/ 你必须添加

protected $except = [
    '/full/route/*',
];

您好像在添加路由名称而不是 URI