title: Laravel form validation for returning dropdown values
body: <p>When a validation fails, I want my dropdowns to have previously selected values in it.My drop down list is populated from javascript. Validation does not validate this dropdown box values.</p>
  
  <p>Drop down list in my view</p>
  
  <pre><code>&lt;div class="form-group"&gt;
    &lt;label align="right" for="ItemID" class="control-label col-xs-2"&gt;Item :&lt;/label&gt;
        &lt;select class="col-md-5 input-sm" name="itemID" id="ItemID" &gt;
           &lt;option&gt;  &lt;/option&gt;             
        &lt;/select&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My java script for loading values</p>
  
  <pre><code>$(document).ready(function(){
       $('#Year').on('click',function(e){
          var year= e.target.value;
            $.getJSON('/xxxxx/xxx?year=' + year, function(data){
  
            $('#ItemID').empty();
             $.each(data,function(index, courses){
               $('#ItemID').append('&lt;option value="'+courses[0].ID+'"&gt;'+courses[0].Code+'&lt;/option&gt;');
             });
          }); 
        });
   });
  </code></pre>
  
  <p>I tried following for getting previously selected values using <a href="https://laracasts.com/discuss/channels/laravel/form-validation-with-old-input?page=1" rel="nofollow noreferrer">this tutorial</a>.</p>
  
  <pre><code>&lt;select class="form-control" name="item" id="item"&gt;
  &lt;option disabled selected&gt;Velg...&lt;/option&gt;
  @foreach ($items as $item)
      &lt;option value="{{ $item-&gt;name }}" @if (old('item') == $item-&gt;name) selected="selected" @endif&gt;{{ $item-&gt;name }}&lt;/option&gt;
  @endforeach
  &lt;/select&gt;
  </code></pre>
  
  <p><strong>PS :</strong> When I use this coding, it returns the ID value, not the code in dropdown box.<br></p>
  
  <pre><code>&lt;div class="form-group"&gt;
      &lt;label align="right" for="ActivityItemsID" class="control-label col-xs-2"&gt;Activity : &lt;/label&gt;
         &lt;select class="col-md-5 input-sm" name="ActivityItemsID" id="ActivityItemsID" &gt;
            &lt;option value="{{Input::old('ActivityItemsID')}}" &gt; {{Input::old('ActivityItemsID')}}  &lt;/option&gt;
                &lt;option value=" "&gt; &lt;/option&gt;
         &lt;/select&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>But It doesn't work. How to get previosly selected values for the form?</p>