-
Notifications
You must be signed in to change notification settings - Fork 774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
validation optional embed attributes #716
Comments
use Respect\Validation\Validator as v;
class Main
{
public $embed;
}
class Required
{
public $required;
}
$requiredTrue = new Required();
$requiredTrue->required = 'here we go';
$mainTrue1 = new Main();
$mainTrue2 = new Main();
$mainTrue2->embed = $requiredTrue;
$requiredFalse = new Required();
$mainFalse = new Main();
$mainFalse->embed = $requiredFalse;
$validator = v::attribute(
'embed',
v::optional(
v::attribute(
'required',
v::length(1, 256)
)
)
);
var_dump($validator->validate($mainTrue1)); // bool(true)
var_dump($validator->validate($mainTrue2)); // bool(true)
var_dump($validator->validate($mainFalse)); // bool(false) I hope this is what you're looking for |
I found that i must use the
|
I'm closing issues that are too old, and I'm not really looking at them all. If this is still relevant, please comment here and I will reopen this issue. Thanks for all your comments! 🐼 |
i try to validate a optional
embed
object in my main object. But it doesn't work.embed
is optionalembed
is set then it must have arequired
valuevalidation code
The text was updated successfully, but these errors were encountered: