Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
logout confirmation message is not working laravel-8

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>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

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.

<a class="dropdown-item" id="logout" data-link="{{ route('admin.logout') }}">
    {{ __('Logout') }}
</a>
<script>
    $(docoment).on("click", "#logout", function(e) {
        e.preventDefault();
        var link = $(this).attr("data-link");
        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>

If you are using jQuery >= 1.4.3, then you can also get the data attribute like

var link = $(this).data("link");
about 4 years ago · Juan Pablo Isaza Denunciar

0

Well I'd prefer to create a form to logout. Get method for logging out is not recommended.

<form action="{{ route('logout') }}" method="post" id="logoutorm">
  @csrf
   <button type="submit" class="dropdown-item">
      <i class="far fa-fw fa-arrow-alt-circle-left mr-1"></i> {{ __('Sign Out') }}
   </button>
 </form>

To submit this form via sweet alert you can do something like this:

<script>
$(document).on("submit", "#logoutorm", function(event) {
    event.preventDefault();
    let form = $(this);
    swal({
            title: "Are you Want to logout?",
            text: "",
            icon: "warning",
            buttons: true,
            dragerMode: true,
        })
        .then((willDelete) => {
            if (willDelete) {
                form.submit();
            } else {
                swal("Logout Canceled");
            }
        });
});

Hope this would work for you :)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda