Fluent crypto

Comment

Author: Admin | 2025-04-28

The sometimes method is the name of the field we are conditionally validating. The second argument is a list of the rules we want to add. If the closure passed as the third argument returns true, the rules will be added. This method makes it a breeze to build complex conditional validations. You may even add conditional validations for several fields at once:1$validator->sometimes(['reason', 'cost'], 'required', function (Fluent $input) {2 return $input->games >= 100;3}); The $input parameter passed to your closure will be an instance of Illuminate\Support\Fluent and may be used to access your input and files under validation.Complex Conditional Array ValidationSometimes you may want to validate a field based on another field in the same nested array whose index you do not know. In these situations, you may allow your closure to receive a second argument which will be the current individual item in the array being validated: 1$input = [ 2 'channels' => [ 3 [ 4 'type' => 'email', 5 'address' => '[email protected]', 6 ], 7 [ 8 'type' => 'url', 9 'address' => 'https://example.com',10 ],11 ],12];13 14$validator->sometimes('channels.*.address', 'email', function (Fluent $input, Fluent $item) {15 return $item->type === 'email';16});17 18$validator->sometimes('channels.*.address', 'url', function (Fluent $input, Fluent $item) {19 return $item->type !== 'email';20});Like the $input parameter passed to the closure, the $item parameter is an instance of Illuminate\Support\Fluent when the attribute data is an array; otherwise, it is a string.Validating ArraysAs discussed in the array validation rule documentation, the array rule accepts a list of allowed array keys. If

Add Comment