http动词用于路由助手功能

时间:2014-04-14 15:24:07

标签: http laravel laravel-4 url-routing

我有一个安静的控制器,我想使用destroy函数 这是我的路线:

 +-------------------------------+-----------------------+----------------------+
 |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()辅助函数中指定http动词?

1 个答案:

答案 0 :(得分:2)

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

表单需要POST到正确的URI:

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

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