使用 .* 在数组 laravel 中验证
validate in array laravel using .*
我尝试使用 'id_s.*' => 'required' 在数组中进行验证,不确定为什么不起作用
UPDATED 我添加了我的 jquery append ,在我的控制器中我使用了我想要的循环 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();
});
});
});
对于select,您不需要在名称中做数组,也不需要在选项中添加名称:
<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'
我尝试使用 'id_s.*' => 'required' 在数组中进行验证,不确定为什么不起作用
UPDATED 我添加了我的 jquery append ,在我的控制器中我使用了我想要的循环 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();
});
});
});
对于select,您不需要在名称中做数组,也不需要在选项中添加名称:
<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'