I want to delete a record using ajax call with laravel 5.4. I tried a lot but delete is is not working means unable to delete records from database. Here is my View:
<div class="btn-sm btn-danger pull-right delete" data-token="{{ csrf_token() }}" s data-id="{{$menus->id}}">
<i class="voyager-trash"></i> Delete
</div>
Script:
<script>
$(document).ready(function () {
$('.delete').click(function(){
var id=$(this).data("id");
var token=$(this).data("token");
$.ajax(
{
url: "skillset/delete/"+id,
type: 'DELETE',
dataType: "JSON",
data: {
"id": id,
"_method": 'DELETE',
"_token": token,
},
success: function ()
{
console.log("okie");
}
});
console.log("not okie");
})
});
</script>
Controller:
public function delete($id)
{
echo'hii';
return $result= Skillset::destroy($id);
}
Route:
// Route skill set
Route::group([
'as' => 'skillset.',
'prefix' => 'skillset',
], function () use ($namespacePrefix) {
Route::get('/', ['uses' => $namespacePrefix . 'Skillsetcontroller@index', 'as' => 'index']);
Route::post('/', ['uses' => $namespacePrefix . 'Skillsetcontroller@store', 'as' => 'store']);
Route::delete('/skillset/delete/{id}', ['uses' => $namespacePrefix . 'Skillsetcontroller@delete', 'as' => 'destroy']);
});
When i click delete button my console give me path like
DELETE
XHR
http://127.0.0.1:8000/admin/skillset/delete/1
Can anyone tell me the solution please..any help would be appreciated.