html - 如何验证 laravel 中的空数组选择框?
问题描述
我正在使用 laravel 开发一个需要一系列选择选项的应用程序
我的代码
<select name="test_id[]" class="form-control select-test-{{$idselect}}"
id="select-{{Illuminate\Support\Str::random(10)}}">
<option value="">Select Patient Test</option>
@foreach ($tests as $item)
<option value="{{$item->id}}">{{$item->name}}</option>
@endforeach
</select>
Laravel 验证码
$request->validate([
'test_id' => 'required:array'
], [
'test_id.required' => "Test is required"
]);
即使没有选择它也会通过
未选中时输出
解决方案
那么您唯一缺少的是multiple
您的选择元素中的属性。
<select multiple name="test_id[]" class="form-control select-test-{{$idselect}}" id="select-{{Illuminate\Support\Str::random(10)}}">
推荐阅读
- javascript - 如何在 Nginx 中阻止 JS 文件
- tableau-api - CountD 在此标题计算字段中无法正常工作
- azure-devops - 如何将自定义上下文菜单项添加到 Azure DevOps 中的工作项上下文菜单
- upload - 使用 jfrog cli 从 stdin 上的文件上传?
- d3.js - D3.js 集群节点重叠
- javascript - 无法使用来自外部组件的事件触发器发出 POST 请求(带数据)
- python - 将两个元组中的交替值添加到空列表(python3)
- laravel - 要么删除类“EligibilityImport”的这个无用的对象实例化,要么使用它
- java - SpringBootTest 用于任意 ApplicationConfiguration 类来测试 application.yml 文件的读取
- google-chrome - 铬和铬的内存占用