我尝试使用' id_s。*'进行数组验证。 => '必需',不确定为什么不起作用
UPDATED 我添加了我的jquery追加,在我的控制器中我使用了我想要的循环id_s
在我的HTML中
<select id="custom-select" class="form-control custom-select" name="id_s[]" >
<option disabled="true" selected="true" name="id_s[]" value="choose">choose</option>
@foreach($subject as $s)
<option value="{{$s->ID}}" name=id_s[]>{{$s->NAME}} / {{$s->CREDIT}} </option>
@endforeach
</select>
$(document).ready(function() {
$('#add-form').click(function() {
i++;
id_i++;
$('#add-me').append(
'<tr>'+
'<td>'+
'<select id="custom-select" name="id_s[]" class="form-control custom-select"><option disabled="true" selected="true" name="id_s[]" value="choose">choose</option>@foreach($subject as $s)<option value="{{$s->ID}}" name=id_s[]>{{$s->NAME}} / {{$s->CREDIT}}</option>@endforeach</select>'
+'</td>'
+'<td>'
+'<button id="'+i+'" type="button" class="btn btn-danger delegated-btn">Delete</button>'
+'</td>'
+'</tr>'
);
$('button.btn.btn-danger').click(function() {
var whichtr = $(this).closest("tr");
whichtr.remove();
});
});
});
答案 0 :(得分:2)
对于选择,您不需要在名称中执行数组,也不需要为选项添加名称:
<select id="custom-select" class="form-control custom-select" name="id_s" >
<option disabled="true" selected="true" value="choose">choose</option>
@foreach($subject as $s)
<option value="{{$s->ID}}" >{{$s->NAME}} / {{$s->CREDIT}}</option>
@endforeach
</select>
和这样的验证:
'id_s' => 'required|not_in:choose'