Required_if laravel with multiple value(required_if laravel 具有多个值)
问题描述
我有一个这样的下拉菜单:
I have a dropdown menu like this:
<select name="selection">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<input type="text" name="stext">
我想要 laravel 中的以下内容:
I want the following in laravel:
public static myfunction(){
$input = Input::only('selection','stext');
$rule = array(
'selection' => 'required',
'stext' => 'required_if:selection,2,3',
);
$validate = Validator::make($input,$rule);
}
但如果我选择选项 1,stext 仍然是必需的.为什么?我该如何解决?
But if I select option 1, stext is still required. Why?
How can I fix it?
推荐答案
正如 LePhleg answer 所指出的,这个验证有一个最好的语法:
As pointed out by LePhleg answer, there is a nicest syntax for this validation:
$rule = array(
'selection' => 'required',
'stext' => 'required_if:selection,2,3,
);
下面的旧答案:
我认为 require_if 验证每次只接受一个值.尝试更改您的验证码如下:
I think that the require_if validation accept only one value per time. Try to change your validation code as below:
$rule = array(
'selection' => 'required',
'stext' => 'required_if:selection,2|required_if:selection,3',
);
检查LePhleg的答案,更干净.在不可能的答案时,只需检查问题,他使用相同的方法但没有工作.
Check LePhleg answer, is more cleaner. At the time of the answer that was not possible, just check the question, he was using the same method but not worked.
这篇关于required_if laravel 具有多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:required_if laravel 具有多个值
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
