Pass parameter to route in javascript in laravel

0

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

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

that passes a parameter to a method in controller of laravel .

  

My question is in javascript how do I put the parameter in the route?

    
asked by anonymous 30.11.2018 / 21:14

1 answer

1

I was able to solve this problem, following the code if someone has the 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 call this:

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

Summarizing the ajax / jquery date parameter, you define the method parameter in the controller. abc.

    
03.12.2018 / 19:34