I laravel I am trying to create a logout confirmation message when I click on my logout button
for this I have done this to my navebar.blade.php
<a class="dropdown-item" id="logout" href="{{ route('admin.logout') }}">
{{ __('Logout') }}
</a>
and this to my admin.blade.php but not working but it should work
<script>
$(docoment).on("click", "#logout", function(e) {
e.preventDefault();
var link = $(this).attr("href");
swal({
title: "Are you Want to logout?",
text: "",
icon: "warning",
buttons: true,
dragerMode: true,
})
.then((willDelete) => {
if (willDelete) {
window.location.href = link;
} else {
swal("Not Logout");
}
});
});
</script>
2
Answers
Here the
<a>
tag doesn’t waits for the click function to execute. It will redirects to the link in href. So change the function as follows.If you are using jQuery >= 1.4.3, then you can also get the data attribute like
Well I’d prefer to create a form to logout. Get method for logging out is not recommended.
To submit this form via sweet alert you can do something like this:
Hope this would work for you 🙂