Advertisement

Responsive Advertisement

Example Sweet alert Confirm in Laravel blade

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>contoh</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

</head>

<body>
<div class=" d-flex justify-content-between mb-2">
<button type="button" class="btn btn-info btn-sm btn-flat" data-toggle="modal" data-target="#modal-default">
<i class="fas fa-plus"></i> Tambah Siswa
</button>
<div>
{{-- <a href="{{ route('students.status', 'baru') }}" class="btn btn-flat btn-outline-info btn-sm">Baru</a>
<a href="{{ route('students.status', 'aktif') }}" class="btn btn-flat btn-outline-info btn-sm">Aktif</a> --}}
</div>

</div>
<table id="datatable" class="display" style="width:100%">
<thead>
<tr>
<th>#</th>
<th>Nama</th>
<th>Kota</th>
<th>Jenis kelamin</th>
<th>No Hp</th>
<th>Aksi</th>
</tr>
</thead>

<tbody>
@foreach ($collection as $item)
<tr>
<th>{{ $loop->iteration }}</th>
<th>{{ $item->nama_lengkap }}</th>
<th>{{ $item->kota }}</th>
<th>{{ $item->jenis_kelamin }}</th>
<th>{{ $item->no_hp }}</th>
<th>
<div class="btn-group">
<a href="{{ route('students.show', $item->id) }}" type="button"
class="btn btn-info">Detail</a>
<button type="button" class="btn btn-info dropdown-toggle dropdown-toggle-split"
data-toggle="dropdown" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{{ route('students.edit', $item->id) }}">Edit</a>
<a class="dropdown-item" target="_blank"
href="{{ route('pdf.biodata', $item->id) }}">Biodata</a>
<a class="dropdown-item" target="_blank"
href="{{ route('pdf.mou', $item->id) }}">MoU</a>
{{-- <a class="dropdown-item" href="{{ route('pdf.biodata') }}">Cetak Kts</a> --}}
<div class="dropdown-divider"></div>
</div>
<form method="POST" action="{{ route('students.destroy', $item->id) }}">
@csrf
<input name="_method" type="hidden" value="DELETE">
<button type="submit" class="btn btn-xs btn-danger btn-flat show_confirm"
data-toggle="tooltip" title='Delete'>Delete</button>
</form>
</div>
</th>
</tr>
@endforeach
</tbody>
</table>

</body>

<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.0/sweetalert.min.js"></script>
<script type="text/javascript">
$('.show_confirm').click(function(event) {
var form = $(this).closest("form");
var name = $(this).data("name");
event.preventDefault();
swal({
title: `Are you sure you want to delete this record?`,
text: "If you delete this, it will be gone forever.",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
form.submit();
}
});
});
</script>

</html>

Posting Komentar

0 Komentar