xenish xenish - 1 month ago 12x
PHP Question

CRUD Laravel 5 how to link to destroy of Resource Controller?

I have a link

<a class="trashButton" href="{{ URL::route('user.destroy',$members['id'][$i]) }}" style="cursor: pointer;"><i class="fa fa-trash-o"></i></a>

this link is supposed to direct to the destroy method of the Usercontroller , this is my route
Route::resource('/user', 'BackEnd\UsersController');

UserController is a Resource Controller. But at this moment it is directing me to the show method rather than directing to the destroy method


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

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:

    url: '/user/4',
    type: 'DELETE',  // user.destroy
    success: function(result) {
        // Do something with the result