我尝试过很多东西,但没有解决方案可以帮我解决,请问如何验证以下情况?
使用JsValidator库 https://github.com/proengsoft/laravel-jsvalidation 正在验证每个其他字段,但不控制数组字段。
HTML
{!! Form::select('country_id[]', $countries, null, ['class' => 'form-control', 'id' => 'country_id', 'multiple' => 'multiple']) !!}
<!-- Laravel Javascript Validation -->
<script type="text/javascript" src="{{ asset('public/vendor/jsvalidation/js/jsvalidation.js')}}"></script>
{!! JsValidator::formRequest('App\Http\Requests\Admin\CampaignRequest') !!}
FormRequest
public function rules()
{
switch ($this->method()) {
case 'PUT':
$rules = [
'title' => 'required|min:3|max:255|unique:campaigns,id,' . $this->get('id'),
'description' => 'required',
'package_id' => 'required',
'country_id' => 'required',
'quantity' => 'required',
'sort' => 'required',
];
break;
default:
$rules = [
'title' => 'required|min:3|max:255|unique:campaigns,id',
'description' => 'required',
'package_id' => 'required',
'country_id' => 'required',
'quantity' => 'required',
'sort' => 'required',
];
break;
}
return $rules;
}
答案 0 :(得分:0)
如果select是多个,则不需要将名称写为数组(country_id而不是country_id [])
{!! Form::select('country_id', $countries, null, ['class' => 'form-control', 'id' => 'country_id', 'multiple' => 'multiple']) !!}