CRUD Laravel 5如何链接到销毁资源控制器? [英] CRUD Laravel 5 how to link to destroy of Resource Controller?
问题描述
我有一个链接
<a class="trashButton" href="{{ URL::route('user.destroy',$members['id'][$i]) }}" style="cursor: pointer;"><i class="fa fa-trash-o"></i></a>
该链接应该直接指向Usercontroller的destroy方法,这是我的路线Route::resource('/user', 'BackEnd\UsersController');
this link is supposed to direct to the destroy method of the Usercontroller , this is my route Route::resource('/user', 'BackEnd\UsersController');
UserController是资源控制器.但是目前,它正在引导我使用show方法,而不是使用destroy方法.
UserController is a Resource Controller. But at this moment it is directing me to the show method rather than directing to the destroy method
推荐答案
这是因为您是通过GET方法而不是DELETE方法来请求资源的.看:
This is because you are requesting the resources via GET method instead DELETE method. Look:
DELETE /photo/{photo} destroy photo.destroy
GET /photo/{photo} show photo.show
两个路由都具有相同的URL,但是标题动词标识要调用的URL.查找 RESTful表.例如,通过ajax,您可以发送DELETE请求:
Both routes have the same URL, but the header verb identifies which to call. Looks the RESTful table. For example, via ajax you can send a DELETE request:
$.ajax({
url: '/user/4',
type: 'DELETE', // user.destroy
success: function(result) {
// Do something with the result
}
});
这篇关于CRUD Laravel 5如何链接到销毁资源控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!