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

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