路由辅助函数的 http 动词

标签 http laravel laravel-4 url-routing

我有一个 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/

相关文章:

C++ - 向客户端发送简单 HTML 的简单服务器

javascript - 如何仅在 Angular 中发出 $http 请求后才运行 javascript 函数?

c# - 404 for web.api cors 选项

http - Netty http 流水线方法验证

node.js - 运行 'react' 时无法解析 "npm run"

php - 类不存在 laravel 5.3

php - Laravel 中 "Resource"路由的不同策略

php - 拉拉维尔 : How to eager load specific columns using hasMany function?

php - 拉维尔 : How to use eloquent ORM to find information of NOT authenticated user?

laravel - 与命名空间的多态 Eloquent 关系