Skip to content

Commit

Permalink
mostrando mensaje de validación consweet alert al intentar eliminar
Browse files Browse the repository at this point in the history
  • Loading branch information
juankno committed Jun 10, 2022
1 parent 67bb598 commit e3c60d5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
27 changes: 24 additions & 3 deletions resources/views/partners/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
<td>{{ $partner->created_at }}</td>
<td>
<a href="{{ route('partners.edit', $partner) }}" class="btn btn-sm btn-primary">Editar</a>
<form action="{{ route('partners.destroy', $partner) }}" method="POST" class="d-inline">
<a class="btn btn-sm btn-danger" onclick="deletePartner('partner-{{ $partner->id }}')">Eliminar</a>
<form action="{{ route('partners.destroy', $partner) }}" method="POST" class="d-none" id="partner-{{ $partner->id }}">
@csrf
@method('DELETE')
<button class="btn btn-sm btn-danger" type="submit">Eliminar</button>
</form>
</td>
</tr>
Expand All @@ -51,4 +51,25 @@
</div>
</div>
</div>
@endsection
@endsection

@push('js')
<script>
function deletePartner(partner) {
Swal.fire({
title: '¿Estas seguro?',
text: "Se eliminará el socio seleccionado",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Si, eliminar!',
cancelButtonText: 'Cancelar',
}).then((result) => {
if (result.value) {
$(`#${partner}`).submit();
}
})
}
</script>
@endpush
27 changes: 24 additions & 3 deletions resources/views/users/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
<td>{{ $user->created_at }}</td>
<td>
<a href="{{ route('users.edit', $user) }}" class="btn btn-sm btn-primary">Editar</a>
<form action="{{ route('users.destroy', $user) }}" method="POST" class="d-inline">
<a class="btn btn-sm btn-danger" onclick="deleteUser('delete-{{ $user->id }}')">Eliminar</a>
<form action="{{ route('users.destroy', $user) }}" method="POST" class="d-none" id="delete-{{ $user->id }}">
@csrf
@method('DELETE')
<button class="btn btn-sm btn-danger" type="submit">Eliminar</button>
</form>
</td>
</tr>
Expand All @@ -57,4 +57,25 @@
</div>
</div>
</div>
@endsection
@endsection

@push('js')
<script>
function deleteUser(user) {
Swal.fire({
title: '¿Estas seguro?',
text: "Se eliminará el usuario seleccionado",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Si, eliminar!',
cancelButtonText: 'Cancelar',
}).then((result) => {
if (result.value) {
$(`#${user}`).submit();
}
})
}
</script>
@endpush

0 comments on commit e3c60d5

Please sign in to comment.