[英]How to call a foreach select box in controller to a blade view with laravel?
I am using laravel 5.2 and I have a field which is a selectbox, and I call it in the controller to show in my view. 我正在使用laravel 5.2,我有一个字段是一个选择框,并在控制器中调用它以在视图中显示。 But The value of the selectbox does not appear. 但是不会显示选择框的值。 When my code in the controller like this: 当我的代码在控制器中这样时:
foreach($getDataListPengikut as $dtListPengikut):
$msg["opt"] .= '<tr>
<td><select class="form-control" id="name_{{ $dtListPengikut->KODE }}" name="name[]" data-live-search="true" style="width:100%">
<option value=""> --Silahkan Pilih-- </option>
@foreach ($getPengikut as $getPeng)
<option value="{{ $getPeng->KODE }}">{{ $getPeng->DESKRIPSI }}</option>
@endforeach
</select>
</td>
<td><input type="text" value="'.$dtListPengikut->KETERANGAN.'" id="ket_'.$dtListPengikut->KODE.'" name="ket[]" placeholder="Keterangan" class="form-control ket_list" style="text-transform:uppercase" required="false" />
</td>
<td><button type="button" name="add" id="add2" class="btn btn-success"><b>+</b></button>
</td>
</tr>';
$no++;
endforeach;
In the inside of my selectbox is {{ $getPeng->DESKRIPSI }}
在我的选择框内部是{{ $getPeng->DESKRIPSI }}
And when I change my code into like this: 当我将代码更改为这样时:
<select class="form-control" id="name_'.$dtListPengikut->KODE.'" name="name[]" data-live-search="true" style="width:100%">
<option value=""> --Silahkan Pilih-- </option>
'. foreach($getPengikut as $getPeng) .'
<option value="'. $getPeng->KODE.'"> '.$getPeng->DESKRIPSI.' </option>
'.endforeach.'
</select>
I got an error : 我有一个错误:
syntax error, unexpected 'foreach' (T_FOREACH) 语法错误,意外的“ foreach”(T_FOREACH)
You're using the wrong syntax. 您使用的语法错误。 Use {{ expression }}
instead of "'.
. The correct syntax is: 使用{{ expression }}
而不是"'.
正确的语法是:
<select class="form-control" id="name_{{ $dtListPengikut->KODE }}" name="name[]" data-live-search="true" style="width:100%">
<option value=""> --Silahkan Pilih-- </option>
@foreach ($getPengikut as $getPeng)
<option value="{{ $getPeng->KODE }}">{{ $getPeng->DESKRIPSI }}</option>
@endforeach
</select>
In the view file :
<select class="form-control" id="name_{{ $dtListPengikut->KODE }}" name="name[]" data-live-search="true" style="width:100%">
<option value=""> --Silahkan Pilih-- </option>
@foreach ($getPengikut as $getPeng)
<option value="{{ $getPeng->KODE }}">{{ $getPeng->DESKRIPSI }}</option>
@endforeach
</select>
In in the controller:
$html = '<select class="form-control" id="name_'.$dtListPengikut->KODE.'" name="name[]" data-live-search="true" style="width:100%">
<option value=""> --Silahkan Pilih-- </option>';
foreach($getPengikut as $getPeng):
$html .= '<option value="'. $getPeng->KODE.'"> '.$getPeng->DESKRIPSI.'</option>' ;
endforeach;
$html .='</select>';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.