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

214
Visualizações
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 Respostas
Responde à pergunta

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