首页 > 解决方案 > 使用路由资源不支持 POST 方法

问题描述

我开始使用 Laravel,我创建了一个小表单和一个资源路由,但我收到了以下错误消息:

The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE.

我的控制器功能代码:

public function store(Request $request)
{
    $data = json_decode($request->payload, true);
    $rules = [
        'compaign_name' => 'digits:8'
    ];

}

我的路线:

Route::resource('/compaign', 'CompaignController');

注意:我的 HTML 表单方法是POST *

标签: phplaravel

解决方案


文档 [ https://laravel.com/docs/7.x/routing]

似乎声称:

CSRF Protection

Any HTML forms pointing to POST, PUT, or DELETE routes that are defined in the web routes file should include a CSRF token field. Otherwise, the request will be rejected. You can read more about CSRF protection in the CSRF documentation:

<form method="POST" action="/profile">
    @csrf
    ...
</form>

推荐阅读