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

215
Vistas
Generate modal with JS containing a Router - laravel

function confirmDelete(ruta, id){
            alert(ruta +","+ id);
            document.getElementById('confirmDeleteModal').innerHTML = '<div class="modal-dialog max-w-2xl">'
                + '<div class="modal-content mx-auto">'
                    + '<div class="modal-header">'
                        + '<button type="button" class="close la la-times" data-dismiss="modal"></button>'
                    + '</div>'
                    + '<div class="modal-body">'
                        + '<h2>¿Está seguro que desea eliminar el registro?</h2>'
                    + '</div>'
                    + '<div class="modal-footer">'
                        + '<div class="flex flex-wrap gap-2">'
                            
                                + '<a  href="{{route('+ ruta +', '+ id +'}}"'
                                    + 'class="btn btn_primary">'
                                    + 'Aceptar'
                                + '</a>'
                            + '<button type="button" data-dismiss="modal"'
                                + 'class="btn btn_outlined btn_secondary uppercase">Cancelar</button>'
                        + '</div>'
                    + '</div>'
                + '</div>'
            +'</div>';
        }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<a onclick="confirmDelete('method.tables.bank-entities.delete','1')" class="btn btn-icon btn_outlined btn_secondary">
  eliminar
</a>
<div id="createModal" class="modal" data-animations="fadeInDown, fadeOutUp">
</div>

I have an anchor that executes a function to remove

<a onclick="confirmDelete('method.tables.bank-entities.delete','1')"
                                    class="btn btn-icon btn_outlined btn_secondary">
                                    <span class="la la-trash"></span>
                                </a>

This function adds the content to a modal The function needs 2 parameters the route and the id to delete

    function confirmDelete(ruta, id){
        alert(ruta +","+ id);
    }

The problem is that it doesn't add the content to the div of the modal and I don't know how to use the "{{route('+ route +', '+ id +'}}" in js

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If I'm not mistaken, what you want is to use a Laravel function (route) but passing the values through javascript, however that is not possible. First the laravel code is executed on the server and the generated result (html and JS) is sent to the client, so you can't call laravel functions directly from javascript.

One way to solve this would be to create your route string using javascript from the received data, without using Laravel code.

+ '<a  href="http:/example.com/'+ ruta +'/'+ id +'"'
     + 'class="btn btn_primary">'
     + 'Aceptar'
     + '</a>' 
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