我正在使用jquery刪除記錄我有2種不同的jquery方法一種是刪除單個記錄在控制器中銷燬方法和其他方法是刪除多個記錄在控制器destroyAll方法 我希望只使用銷燬方法無論是在控制器中刪除所有單個和多個記錄boyh可以處理,我使用資源控制器 這裏下面添加2在laravel中刪除方法Destroy方法(Laravel 5.3)
我的方法對單個記錄jQuery的方法
function studentDelete(id) {
if(confirm('Are you sure to delete this User!')) {
$("#row_"+id).attr("style", "display:none");
$.ajax({
url: '/student/'+id,
type: "DELETE",
success: function(result) {
if(result == 'delete') {
$('#message').show();
$('#message-text').html('successfully deleted.');
$('#message').removeClass('displayhide').addClass('alert alert-success display-show');
}
}
});
}
}
多個記錄的jQuery的方法
function deleteAll() {
if(!$('input:checkbox:checked').length){
alert("Nothing Selected");
return false;
}
if(confirm('Are you sure!')) {
var checkedValues = $('input:checkbox:checked').map(function() {
return this.value;
}).get();
$.ajax({
type : "POST",
url : "{{ url('/school-management/student/destroyAll') }}",
data : {ids: checkedValues, _token: "{{ csrf_token() }}"},
success: function(result) {
if(result == 'delete') {
window.location.href = "/dashboard";
}
}
});
}
}
控制器方法對於單個記錄
public function destroy($id)
{
$student = Student::findOrFail($id);
$student->delete();
return 'delete';
}
控制器方法對於單個記錄
public function destroyAll(Request $request)
{
$ids = $request->input('ids');
$school = Student::whereIn('id', $ids);
$school->delete();
session()->flash('msg',trans('deleted successfully.'));
return 'delete';
}
路由
Route::resource('/student', 'SchoolController');
我希望只使用一個方法,就是消滅同時處理一個和多個刪除記錄 我有想法,但不知道如何使用它 它是隻是爲了檢查這一要求我來從該方法從studentDelete或從deleteAll