CRUD Laravel 5 如何链接到资源控制器的销毁?

CRUD Laravel 5 how to link to destroy of Resource Controller?(CRUD Laravel 5 如何链接到资源控制器的销毁?)
本文介绍了CRUD Laravel 5 如何链接到资源控制器的销毁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个链接

<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 如何链接到资源控制器的销毁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

In PHP how can you clear a WSDL cache?(在 PHP 中如何清除 WSDL 缓存?)
failed to open stream: HTTP wrapper does not support writeable connections(无法打开流:HTTP 包装器不支持可写连接)
Stop caching for PHP 5.5.3 in MAMP(在 MAMP 中停止缓存 PHP 5.5.3)
Caching HTTP responses when they are dynamically created by PHP(缓存由 PHP 动态创建的 HTTP 响应)
Memcached vs APC which one should I choose?(Memcached 与 APC 我应该选择哪一个?)
What is causing quot;Unable to allocate memory for poolquot; in PHP?(是什么导致“无法为池分配内存?在 PHP 中?)