http verb for route helper function

穿精又带淫゛_ 提交于 2019-12-24 06:57:07

问题


I have a restful controller and I want to use the destroy function this is my route :

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

I'm using this link

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

And it is always calling the show($id) function. So the it is using the GET verb instead of DELETE. Is there a way to specify the http verb in the route()helper function?


回答1:


You need to create a form to do that.

The form needs to POST to the right URI:

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

Information on Laravel forms can be found here



来源:https://stackoverflow.com/questions/23063966/http-verb-for-route-helper-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!