【问题标题】:The POST method is not supported using route resource使用路由资源不支持 POST 方法
【发布时间】:2020-04-16 00:00:18
【问题描述】:

我开始使用 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');

NB : 我的 HTML 表单方法是 POST *

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    文档 [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>
    

    【讨论】:

    • 没关系,问题出在我将“/compaign/store”更新为“/compaign”的操作中
    猜你喜欢
    • 2021-01-21
    • 1970-01-01
    • 2020-09-04
    • 2019-08-23
    • 2019-10-16
    • 2020-04-13
    • 1970-01-01
    • 2023-02-05
    • 2020-12-05
    相关资源
    最近更新 更多