我正在使用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