問題描述
我有一個鏈接
<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', 'BackEndUsersController');
this link is supposed to direct to the destroy method of the Usercontroller , this is my route Route::resource('/user', 'BackEndUsersController');
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,但標頭動詞標識要調用的路由.查看 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 如何鏈接到資源控制器的銷毀?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!