【问题标题】:Laravel routing to <ResourceController>.destroy from an input form (in *.blade.php) using ResourceControllerLaravel 使用 ResourceController 从输入表单(在 *.blade.php 中)路由到 <ResourceController>.destroy
【发布时间】:2017-06-27 19:14:07
【问题描述】:

我有一个数据库表,每一行都有一个名为 id 的主键。我想创建一个页面来删除 id 使用以下表单提交的行:

<form action="{{ route('Account.destroy') }}" method="DELETE">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    <input type="text" name="id">
    <button type="submit"> Delete My Account </button>
</form>

但表单没有按预期工作!

I got these errors

发现需要将id传到{{ route() }},于是尝试{{ route('['Account.destroy', id]' ) 然后出现这些错误:

The errors' page with conducted id to route()

我知道 route(['Account.destroy', id]) 的方法是错误的,但我不知道如何解决这个问题。请帮我!谢谢!

P/s:对不起,如果我的英语太糟糕了!

【问题讨论】:

    标签: php rest crud laravel-5.4


    【解决方案1】:

    你和第二个很接近。你需要这样的东西:

    {{ route('Account.destroy', ['account' => $id]) }}
    

    请参阅this section of the docs 了解更多信息。

    【讨论】:

      【解决方案2】:

      @Samsquanch 是对的。此外,表单的方法应该是 'POST' 并在表单内添加以下行:

      &lt;input name="_method" type="hidden" value="DELETE"/&gt;

      【讨论】:

      • 谢谢。但是当我使用带有路由的普通控制器声明时它仍然有效
      猜你喜欢
      • 2021-12-27
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-21
      • 2020-01-11
      • 1970-01-01
      相关资源
      最近更新 更多