【问题标题】:Laravel forcing POST routes into GETLaravel 强制 POST 路由进入 GET
【发布时间】:2018-10-15 16:31:42
【问题描述】:

路由器:

Route::post('/submit/{id}', function() {
    return 'Hello World';
});

HTML:

<form method="POST" action="/submit/{{$id}}">

以上将URL改为http://127.0.0.1:8000/submit/$id并返回

页面因不活动而过期。

看起来 Laravel 正试图将 POST 强制转换为 GET。

【问题讨论】:

  • Page has expired 的这个答案:stackoverflow.com/a/46141940/9613505
  • 我认为您在 POST 请求中使用了 get 类型路由。检查这个Route Parameters
  • @Hussein,谢谢,工作
  • @seamus 我认为 html 中的 $id 未解析,您确定 html 名称类似于:example.blade.php 吗?

标签: laravel post get routing laravel-5.4


【解决方案1】:

这个问题是因为您忘记将 CSRF 令牌字段放入表单中。

尝试:

选项 1

<form method="POST" action="{{url('submit', [$id])}}">
    {{ csrf_field() }}
    <button type="submit">Submit</button>
</form>

选项 2

<form method="POST" action="{{url('submit')}}/{{$id}}">
    @csrf
    <button type="submit">Submit</button>
</form>

更多信息请看link

【讨论】:

    猜你喜欢
    • 2018-04-20
    • 2015-05-28
    • 2016-04-21
    • 2013-11-08
    • 2016-02-27
    • 2021-08-31
    • 2017-11-11
    • 1970-01-01
    相关资源
    最近更新 更多