title: Populate dropdown based on another dropdown selected value in laravel - edit form
body: <p>I found how to accomplish this on another site and I got it working. My issue is though that I need to use it in my edit form (preferably in the same form as my create form, since my create and edit views use the same form). When I go to my edit page, the "Section" dropdown value is selected as it should be. But the "Subsection" is not, because ofcourse I did not click it. Probably it's a fix too easy for me to see, but I am not quite good with javascript. I basically need the second dropdown (the subsection one) to show the correct options based on which "section" (first dropdown) is selected, on my edit view.</p>
  
  <p>Section Model:</p>
  
  <pre><code>public function subsections()
  {
      return $this-&gt;hasMany('App\Subsection');
  }
  </code></pre>
  
  <p>Subsection Model:</p>
  
  <pre><code>public function section()
  {
      return $this-&gt;belongsTo('App\Section');
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>{!! Form::select('section_id', [null=&gt;'-- Select Section --'] + $sections, null, array('id' =&gt; 'section')) !!}
  
  &lt;select id="subsection" name="subsection_id" class="select"&gt;
      &lt;option&gt;-- First Select Section --&lt;/option&gt;
  &lt;/select&gt;
  
  From my controller: $sections = Section::lists('section', 'id');
  </code></pre>
  
  <p>Script:</p>
  
  
  
  <pre><code>&lt;script&gt;
  $(document).ready(function($){
      $('#section').change(function(){
          $.get("{{ url('api/dropdown')}}", 
          { option: $(this).val() }, 
          function(data) {
              $('#subsection').empty(); 
              $.each(data, function(key, element) {
                  $('#subsection').append("&lt;option value='" + key +"'&gt;" + element + "&lt;/option&gt;");
              });
          });
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Route:</p>
  
  <pre><code>Route::get('api/dropdown', function(){
      $id = Input::get('option');
      $subsections = Section::find($id)-&gt;subsections;
      return $subsections-&gt;lists('subsection', 'id');
  });
  </code></pre>