如何在Laravel 5.2中的路由中使用删除方法 [英] how to use delete method in route in laravel 5.2
本文介绍了如何在Laravel 5.2中的路由中使用删除方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的laravel项目中使用删除路由.
喜欢并想从锚标记的href发送路由.
是否可以在从定位标记的"href"开始的路线
I want to use delete route in my laravel project.
like and want to send route from href of a anchor tag.
is it possible to use delete method in route from "href" of anchor tag
Route::delete('/news/{id}', 'NewsController@destroy');
推荐答案
您不能使用带有href的定位标记来发送删除请求.您需要执行此操作.使用方法 Delete ,因为在表单中我们只能获取和发布,因此请创建一个名称为_method且值为 DELETE 的隐藏字段. 创建类似于此的表单:
You can't use anchor tag with href to send the request to delete. You need a form todo so. With a method DELETE since in form we have only get and post so create a hidden field with name _method and value DELETE Create form similar to this :
<form action="news/id" method="post">
<input type="hidden" name="token" value="{{csrf_token}}" >
<input type="hidden" name="_method" value="DELETE" >
<input type="submit" value="delete " >
</form>
这篇关于如何在Laravel 5.2中的路由中使用删除方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文