Я пытаюсь удалить данные с помощью ajax в laravel 5.8
это моя таблица в виде ролей
<table id="example" class="table table-bordered table-striped">
<thead>
<tr>
<th>Role User</th>
<th>action</th>
</tr>
</thead>
<tbody>
@foreach ($roles as $role)
<tr>
<td>{{ $role->nama }}</td>
<td>
<button type="button" class="delete btn btn-danger" data-toggle="modal"
data-target="#modal-danger" data-id="{{ $role->id }}">
<i class='fa fa-trash'> </i> Delete
</button>
</td>
</tr>
@endforeach
</tbody>
<tfoot>
</tfoot>
</table>
это мой модальный
<div class="modal modal-danger fade" id="modal-danger">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title">Are you sure ?</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline pull-left" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-outline" id="delete_ok" name="delete_ok">Delete</button>
</div>
</div>
</div>
это моя функция javascript
$(document).on('click', '.delete', function () {
$('#modal-danger').show();
var id = $(this).data("id");
$('#delete_ok').click(function () {
$.ajax({
url: "roleuser/" + id,
type: "DELETE",
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data: {},
success: function (data) {
console.log(id);
$('#modal-danger').hide();
location.reload();
},
error: function (data) {
console.log(data);
}
})
});
});
это мой маршрут и контроллер
Route::resource('roleuser', 'RoleUserController');
public function destroy(RoleUser $id)
{
$roleuser = RoleUser::find($id);
$roleuser->deleted_at = date("Y-m-d h:i:s", time());
$roleuser->save();
return redirect()->route('roleuser.index')->with('alert-success', 'Deleted User Role successfully !');
}
я уже добавляю метатег в главном представлении
<meta name="csrf-token" id="csrf-token" content="{{ csrf_token() }}">
когда я проверяю: php artisan route: список. как это:
| | DELETE | roleuser/{roleuser} | roleuser.destroy | App\Http\Controllers\RoleUserController@destroy | web,auth |
но когда я пытаюсь удалить данные, в консоли показать идентификатор, но все равно не перейти к моему контроллеру ... может кто-нибудь помочь ?? что не так в моем коде?
thankyouu:)