【问题标题】:The POST method is not supported for this route. Supported methods: PUT, PATCH, DELETE此路由不支持 POST 方法。支持的方法:PUT、PATCH、DELETE
【发布时间】:2019-04-12 11:17:13
【问题描述】:

它不工作 显示这个

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException 此路由不支持 POST 方法。支持的方法:PUT、PATCH、DELETE。

<form class="form-ad" action="{{ route('jobs.store') }}" method="post" >

【问题讨论】:

  • 所以允许 POST 或伪造PUT/PATCH
  • 错误信息从字面上告诉你一切。你写了method="post",错误告诉你不能使用POST。它甚至告诉你可以使用 PUT、PATCH 或 DELETE。

标签: php web laravel-5 eloquent


【解决方案1】:

在表单标签中伪造你的补丁请求

<form class="form-ad" action="{{ route('jobs.store') }}" method="post" >
{{ method_field('POST') }} /*here i used post and solved the error*/ /*if you are using form method POST then what is the use of using {{method_field('POST')}} form "store" action? {{method_field('POST')}} is mainly used if you have a PATCH request for update action. Store action is already on POST request in your Routes.*/
<!-- rest of the form -->
</form>

另外,只是一个建议,您可以简单地制作资源完整路线。

首先通过 artisan 命令创建一个资源丰富的控制器,它将创建每个方法所需的所有方法(get、post、patch 等)

php artisan make:controller Jobs -r

然后在你的 routes/web.php 中使用

Routes::resource('jobs');

您还可以使用 php artisan 命令查看您的路线

php artisan route:list

【讨论】:

    【解决方案2】:

    可用的路由器方法 路由器允许您注册响应任何 HTTP 动词的路由:

    Route::get($uri, $callback);
    Route::post($uri, $callback);
    Route::put($uri, $callback);
    Route::patch($uri, $callback);
    Route::delete($uri, $callback);
    Route::options($uri, $callback);
    

    https://laravel.com/docs/5.8/routing

    【讨论】:

      【解决方案3】:

      在 html 视图中添加@csrf 行 然后它工作发布方法

      add @csrf line in the html view 
      then it work post method
      -------------------------------------------------------------------
      
      <form  method="post" action="users" class="UserController">
          {{method_field('post')}}
          @csrf
          <input type="text" name="user" placeholder="enter name"><br/><br/>
          <input type="password" name="password" placeholder="enter password"><br/><br/>
          <button type="submit" value="submit">Submit</button>
      </form>

      【讨论】:

        猜你喜欢
        • 2020-04-11
        • 2021-02-01
        • 2021-09-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-13
        • 2020-08-27
        • 2019-10-11
        相关资源
        最近更新 更多