Skip to content

required() and optional()

Rules are required by default. Use optional() to accept null or an empty string, or use required(false) for the same behavior.

use Fynix\Rule;
$required = Rule::string('name')->required();
$optional = Rule::string('nickname')->optional();
$explicit = Rule::string('phone')->required(false);

requiredState() reads the configured state. These methods return immutable clones.