I have a problem in laravel for confirming the post delete by sweetalert
<script>
!function ($) {
"use strict";
var SweetAlert = function () {
};
//examples
SweetAlert.prototype.init = function () {
$('.sa-remove').click(function () {
swal({
title: "are u sure?",
text: "lorem lorem lorem",
type: "error",
showCancelButton: true,
confirmButtonClass: 'btn-danger waves-effect waves-light',
confirmButtonText: "Delete",
cancelButtonText: "Cancel",
closeOnConfirm: true,
closeOnCancel: true
},
function(){
window.location.href = "{{ route('panel.posts.remove',$post->id) }}";
});
});
},
//init
$.SweetAlert = new SweetAlert, $.SweetAlert.Constructor = SweetAlert
}(window.jQuery),
//initializing
function ($) {
"use strict";
$.SweetAlert.init()
}(window.jQuery);
</script>
But I have a foreach
in the view and it just passes last foreach
post id
and when I want to delete for example second post in the table, last one deletes!
this is the table:
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>Body</th>
<th>Author</th>
<th>Operations</th>
</tr>
</thead>
<tbody>
@foreach($posts as $post)
<tr>
<td>{{ $post->id }}</td>
<td>{{ $post->title }}</td>
<td>{{ $post->body }}</td>
<td>{{ $post->user->name }}</td>
<td>
<a href="#" class="sa-remove"><button class="wave-effect btn btn-danger btn-bordred wave-light"><i class="fa fa-times"></i></button></a>
</td>
</tr>
@endforeach
</tbody>
and I'm new in this of course!