【问题标题】:http verb for route helper function路由辅助功能的 http 动词
【发布时间】:2014-04-14 15:24:07
【问题描述】:

我有一个安静的控制器,我想使用销毁功能 这是我的路线:

 +-------------------------------+-----------------------+----------------------+
 |URI                            |Name                   |Action                |
 +-------------------------------+-----------------------+----------------------+
 |GET|HEAD playwright/play/{play}|playwright.play.show   |PlayController@show   |
 +-------------------------------+-----------------------+----------------------+
 |DELETE playwright/play/{play}  |playwright.play.destroy|PlayController@destroy|
 +-------------------------------+-----------------------+----------------------+

我正在使用这个链接

<a href="{{action('PlayController@destroy', $play->id)}}">Delete</a>

而且它总是调用show($id) 函数。所以它使用 GET 动词而不是 DELETE。 有没有办法在route()helper 函数中指定http动词?

【问题讨论】:

    标签: http laravel laravel-4 url-routing


    【解决方案1】:

    您需要创建一个表单来执行此操作。

    表单需要 POST 到正确的 URI:

    {{ Form::open(array('url' => URL::route('playwright.play.destroy'), 'method' => 'DELETE')) }}
        {{ Form::submit('Delete me!')}}              
    {{ Form::close() }}
    

    关于 Laravel 表单的信息可以在here找到

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-30
    • 2019-01-23
    相关资源
    最近更新 更多