Pass parameter for route in javascript in Laravel

Asked

Viewed 1,193 times

0

Good afternoon, I have a question about parameters in laravel that I didn’t find on the site, I have a route like this:

Route::get('busca/{id}', 'MatriculasController@busca'); 

passing a parameter to a method in the controller of laravel.

My doubt is in the javascript how do I place the parameter on the route?

  • Can someone help me with this question please?

  • It depends, because you will have to send a request via ajax to get the return of json. There are three native ways to work with javascript in the "depending on version" format, they are pure javascript "vanilla js", jquery and Vue.js

1 answer

1

I managed to solve, follow the code in case someone is with this same problem:

  $(document).ready(function () {
        fetch_customer_data();

     function fetch_customer_data(query = '')
     {
      $.ajax({
       url:"{{ route('live_search.action') }}",
       method:'GET',
       data:{query:query},
       dataType:'json',
       success:function(data)
       {
        $('tbody').html(data.table_data);
        $('#total_records').text(data.total_data);
       }
      });
     }

     $(document).on('keyup', '#search', function(){
      var query = $(this).val();
      fetch_customer_data(query);
     });
     });

In the controller simply calls:

$query = $request->get('query');

Summarizing in the ajax/jquery date parameter defines the method parameter in the controller. abç.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.