Laravel 路由:伪造表单方法 Draft
表单方法伪造
HTML 表单不支持 PUT
、PATCH
或 DELETE
行为。所以当你要从 HTML 表单中调用定义了 PUT
、 PATCH
或 DELETE
行为的路由时,你将需要在表单中增加一个隐藏的 _method
输入标签。使用 _method
字段的值作为 HTTP 的请求方法:
<form action="/foo/bar" method="POST">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
你也可以使用 @method
模板指令生成 _method
输入:
<form action="/foo/bar" method="POST">
@method('PUT')
@csrf
</form>
You may use the method_field helper to generate the _method input:
{{ method_field('PUT') }}