CakePHP 3 Tutorial 21: Conditional Validation

Submitted by naidim on Fri, 01/20/2017 - 12:21

CakePHP's validation is very robust, and while this is immensely helpful, getting to grips with all its possibilities can be daunting.

One handy feature is Conditional Validation. When adding a record, what if we want to ensure a field is not empty only when a matching field is also not empty? For example a schedule for work should have a start time and an end time, but if you wanted to schedule the day off it would have neither.