title: laravel 5 simple ajax retrieve record from database
body: <p>How can I retrieve data using ajax? I have my ajax code that I've been using in some of my projects when retrieving records from database but dont know how to make it in laravel 5 because it has route and controller.</p>
  
  <p>I have this html</p>
  
  <pre><code>&lt;select name="test" id="branchname"&gt;
      &lt;option value="" disabled selected&gt;Select first branch&lt;/option&gt;
      &lt;option value="1"&gt;branch1&lt;/option&gt;
      &lt;option value="2"&gt;branch2&lt;/option&gt;
      &lt;option value="3"&gt;branch3&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;select id="employees"&gt;
      &lt;!-- where the return data will be put it --&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>and the ajax</p>
  
  <pre><code>$("#branchname").change(function(){
      $.ajax({
          url: "employees",
          type: "post",
          data: { id : $(this).val() },
          success: function(data){
              $("#employees").html(data);
          }
      });
  });
  </code></pre>
  
  <p>and in my controller, I declared 2 eloquent models, model 1 is for branchname table and model 2 is for employees table</p>
  
  <pre><code>use App\branchname;
  use App\employees;
  </code></pre>
  
  <p>so I could retrieve the data like (refer below)</p>
  
  <pre><code>public function getemployee($branch_no){
      $employees = employees::where("branch_no", '=', $branch_no)-&gt;all();
      return $employees;
  }
  </code></pre>
  
  <p>how to return the records that I pulled from the employees table? wiring from routes where the ajax first communicate to controller and return response to the ajax post request?</p>
  
  <p>any help, suggestions, recommendations, ideas, clues will be greatly appreciated. Thank you!</p>
  
  <p>PS: im a newbie in Laravel 5.</p>