보기에 범주가 나열되어 있습니다. 카테고리 삭제 단추는 뷰에 있으며 클릭하면 카테고리가 작동하고 삭제됩니다.Laravel 5.2 - Sweet Alert 확인 상자
내가하고 싶은 일은 카테고리를 삭제하기 전에 달콤한 경고 대화 상자가 나타나서 확인을 요청하는 것입니다. 확인 된 경우 정의 된 경로로 이동하여 카테고리를 삭제해야합니다.
<a id="delete-btn" href="{{ route('admin.categories.destroy', $category->id) }}" class="btn btn-danger">Delete</a>
를하고 스크립트는 다음과 같이 정의된다 :
삭제 링크는 다음과 같이 정의된다
<script>
$(document).on('click', '#delete-btn', function(e) {
e.preventDefault();
var link = $(this);
swal({
title: "Confirm Delete",
text: "Are you sure to delete this category?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: true
},
function(isConfirm){
if(isConfirm){
window.location = link.attr('href');
}
else{
swal("cancelled","Category deletion Cancelled", "error");
}
});
});
</script>
그러나, 나는이 범주를 삭제 삭제 버튼을 클릭하면,하지만 달콤한 경고 메시지가 표시되지 않습니다.
Route::get('/categories/destroy/{category}', [
'uses' => '[email protected]',
'as' => 'admin.categories.destroy',
]);
및 제어기 기능은 다음과 같이 정의된다 :
경로는 다음과 같이 정의되는 어떤 도움이 인정 될 것이다
public function destroy(Category $category)
{
$category->delete();
//this alert is working fine. however, the confirmation alert should appear
//before this one, which doesn't
Alert::success('Category deleted successfully', 'Success')->persistent("Close");
return redirect()->back();
}
. 감사.
일했습니다! 고마워. – byteseeker