title: How to pass the data with AJAX to Controller in Laravel?
body: <p>I am really stuck with AJAX request/response in Laravel and would be glad if someone could help me.</p>
  
  <p><strong>This is my JS Ajax:</strong> </p>
  
  <pre><code>$('#manufacturer_id').change(function(){
    var manuf_id = $(this).val();
    console.log("1:"+manuf_id);
  
    var dataString = '{manufacturer_id:'+ manuf_id+'}';
    console.log("2:"+dataString);
  
    // Ajax
    $.ajax({
      url: "/laravel/public/posts/create",
      type: 'GET',
      data: dataString,
      cache: false,
      success: function(data) {
        console.log(dataString);
      },
    });
  });
  </code></pre>
  
  <p><strong>And this is the PostsController, where I need to change just one ID:</strong></p>
  
  <pre><code>public function create(Request $manuf_id)
      {
          $title = 'Add post';
  
          $categories = Category::all();
          $manufacturers = Manufacturer::all();
          $fuels = Fuel::all();
  
          $sendedID = \Response::json($manuf_id);
          $cars = Car::where('manufacturer_id', $sendedID)-&gt;get();
  
          return view('posts.create',
              compact(
                  'title',
                  'categories',
                  'fuels',
                  'cars',
                  'manufacturers'
              )
          );
      }
  </code></pre>
  
  <p>What I really want to achieve: When user select manufacturer from select box in my form, the ID of manufacturer will change the ID which is written here:</p>
  
  <pre><code>$cars = Car::where('manufacturer_id', $sendedID)-&gt;get();
  </code></pre>
  
  <p>Basically when I hardcode the number (ID) instead of variable $sendedID, I get everything I need (I already have releationships between the tables in my database).</p>
  
  <p>All I need to do is to send the value (onchange) of manufacturer and pass it to variable $sendedID in my PostsController. I probably need to change the code in my PostController, just don't know how and I've already researched a lot, but could not find the answer. Thank anybody who has an idea how to repair this.</p>