Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

634
Visualizações
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>
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

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");
over 4 years ago · Santiago Trujillo Relatório

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 :)

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda