required_with 和 required_with_all laravel 验证有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44644016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's is the difference between required_with and required_with_all laravel validation
提问by bathulah mahir
I already tried have a look at https://laravel.com/docs/5.4/validationbut still , i don't really get what's is the difference between :
我已经试过看看https://laravel.com/docs/5.4/validation但仍然,我真的不明白两者之间的区别是什么:
required_with_all
required_with_all
and
和
required_without
required_without
Anyone can explain to me in detail what's the difference ?
任何人都可以向我详细解释有什么区别?
回答by R?sh?Kêsh Kümar
required_with_all :
required_with_all :
Laravel Doc:The field under validation must be present only if allof the other specified fields are present.
Laravel Doc:仅当所有其他指定字段都存在时,验证字段才必须存在。
required_without_all :
required_without_all :
Laravel Doc:The field under validation must be present and not empty only when all of the other specified fields are not present.
Laravel Doc:仅当所有其他指定字段都不存在时,验证字段必须存在并且不能为空。
Example:
例子:
$rules = array(
'facebook_id' => 'required_without_all:twitter_id,instagram_id',
'twitter_id' => 'required_without_all:facebook_id,instagram_id',
'instagram_id' => 'required_without_all:facebook_id,twitter_id',
);
$validator = Validator::make(Input::all(), $rules);
required_with:
required_with:
Laravel Doc:The field under validation must be present only if anyof the other specified fields are present.
Laravel Doc:仅当存在任何其他指定字段时,验证字段才必须存在。
Example:
例子:
$rules = array(
'sell' => 'required_without:rent',
'rent' => 'required_without:sell',
'price' => 'required_with:sell|numeric|min:0',
);
回答by Govind Samrow
required_with:
required_with:
The field under validation must be present and not empty only if anyof the other specified fields are present.
仅当存在任何其他指定字段时,验证中的字段必须存在且不能为空。
required_with_all:
required_with_all:
The field under validation must be present and not empty only if allof the other specified fields are present.
仅当所有其他指定字段都存在时,验证中的字段必须存在且不能为空。
Note: Check bold text above.
注意:检查上面的粗体文本。
For more detail see Laravel docs
有关更多详细信息,请参阅 Laravel文档