我有一个 restful Controller ,我想使用 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()
helper 函数中指定 http 动词?
最佳答案
您需要创建一个表单来执行此操作。
表单需要 POST 到正确的 URI:
{{ Form::open(array('url' => URL::route('playwright.play.destroy'), 'method' => 'DELETE')) }}
{{ Form::submit('Delete me!')}}
{{ Form::close() }}
可以找到有关 Laravel 表单的信息 here
关于路由辅助函数的 http 动词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23063966/