mardi 26 décembre 2017

php foreach radio button with value from database in edit mode

So I have this table than you can choose which customer representative you want from the group. (Can only choose 1, so I use radio button).

My code is like:

<tbody>
      <tr>
      @foreach($customerDetails as $item)
           <td><input name="main_customer_id" type="radio"
           @if(empty($customer_group->main_customer_id)) 
                 value=""
                 @if($item->customer_id == 1)
                     checked
                 @endif
           @endif></td>
           <td></td>
           <td> </td>
           <td></td>
           <td></td>
           <td>  </td>
           <td></td>
           <td></td>
           <td></td>
      </tr>
      @endforeach
</tbody>

I assigned customer_id as value in radio button, I could use some code like

@if($customer_group->id == 1)
    checked
@endif

But the value is dynamic, How do I do it?

Aucun commentaire:

Enregistrer un commentaire