I have being searching everywhere for the past 6 hours and I can't find the answer to my question. I have a data table that display a list of users. I have an column that has an icon that looks like a trash can. The idea is when a user press the icon that gets erase using ajax. This is my first time using ajax and laravel.
This is my view
<td>
<button class="btn btn-danger btn-xs" id="destroy" data-id="5"><i class="fa fa-trash-o "></i>
</button>
</td>
This is my script
$(document).ready(function(){
$("#destroy").click(function()
{
var id = $(this).data("id");
$.ajax(
{
url: "http://localhost:8888/users/destroy",
type: 'DELETE',
dataType: "JSON",
data: {
"id": id
},
success: function ()
{
console.log("it Work");
}
});
console.log("It failed");
})
});
This is my route
Route::delete('users/destroy', 'UsersController@destroy');
this is my controller
public function destroy()
{
$id = input::get('id');
$id = User::findorfail($id);
$id->delete();
}
This the errror I get
TokenMismatchException in VerifyCsrfToken.php line 46:\
destroyclass to them rather than ID.