Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
el mensaje de confirmación de cierre de sesión no funciona laravel-8

Laravel. Estoy tratando de crear un mensaje de confirmación de cierre de sesión cuando hago clic en mi botón de cierre de sesión. He hecho esto en mi navebar.blade.php.

 <a class="dropdown-item" id="logout" href="{{ route('admin.logout') }}"> {{ __('Logout') }} </a>

y esto a mi admin.blade.php pero no funciona pero debería funcionar

 <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 answers
Answer question

0

Aquí, la etiqueta <a> no espera a que se ejecute la función de clic. Redireccionará al enlace en href. Así que cambie la función de la siguiente manera.

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

Si está utilizando jQuery> = 1.4.3, también puede obtener el atributo de datos como

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

0

Bueno, preferiría crear un formulario para cerrar sesión. No se recomienda obtener el método para cerrar sesión.

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

Para enviar este formulario a través de Sweet Alert, puede hacer algo como esto:

 <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"); } }); });

Espero que esto funcione para ti :)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!