i use laravel 4.2, in my project, i use option bottomn and checkbox, data stored in database :

  1. id = 1 | title = base1
  2. id = 2 | title = base2

now, how can i in this code, checked option btn with data stored :

<div class="col-md-4">
   <div class="radio-list">
      @foreach($base as $ba)
         <label for="base-label-{{$ba->id}}">
            <div class="radio" id="label-{{$ba->id}}"><input type="radio" name="base" id="base-label-{{$ba->id}}" value="{{$ba->id}}"  {{ !empty($ba->id)  ? 'checked' : '' }}></div> {{$ba->title}}
         </label>
      @endforeach
   </div>
</div>

1 Answers

0
Hasta Dhana On

Consider you have the retrieved id data from database as $ba_id, you could compare it lik this :

<div class="col-md-4">
    <div class="radio-list">
        @foreach($base as $ba)
            <label for="base-label-{{$ba->id}}">
                <div class="radio" id="label-{{$ba->id}}"><input type="radio" name="base" id="base-label-{{$ba->id}}" value="{{$ba->id}}"  {{ !empty($ba->id) && ($ba_id == $ba->id)  ? 'checked' : '' }}></div> {{$ba->title}}
            </label>
        @endforeach
    </div>
</div>