Kir*_*iva 4 validation laravel-5.2
public function rules() {
return [
'num_of_devices' => 'integer'
];
}
Run Code Online (Sandbox Code Playgroud)
当且仅当输入字段时,我想验证整数字段.但是,即使字段为空,上面的规则也会将其验证为整数.我用过somtimes,但没有结果.但当我var_dump($num_of_devices)是string.I使用Laravel 5.2.我认为它在5.1中运行良好.
nas*_*sor 13
从版本中5.3你可以使用nullable
public function rules() {
return [
'num_of_devices' => 'nullable | integer'
];
}
Run Code Online (Sandbox Code Playgroud)
如果输入不为空,则向数组添加规则。您可以将所有验证规则收集到 $rules 数组,然后返回该数组。
if( !empty(Input::get('num_of_devices')) ){
$rules['num_of_devices'] = 'integer';
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5214 次 |
| 最近记录: |