From 1b8dee7fb70bad23190cbbc6b26096d647e001fa Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 15 Apr 2016 22:04:29 -0400 Subject: [PATCH] Document array form of requirePresence() Refs #3906 --- en/appendices/3-3-migration-guide.rst | 6 ++++++ en/core-libraries/validation.rst | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/en/appendices/3-3-migration-guide.rst b/en/appendices/3-3-migration-guide.rst index e76267dec8..8d52ad3132 100644 --- a/en/appendices/3-3-migration-guide.rst +++ b/en/appendices/3-3-migration-guide.rst @@ -52,6 +52,12 @@ ORM ``unique()`` method, but ensures that association conditions are applied. - ``isUnique`` rules now apply association conditions. +Validation +========== + +- ``Validator::requirePresence()`` now accepts a list of fields. This allows you + to more concisely define the fields that are required. + Debugging Functions =================== diff --git a/en/core-libraries/validation.rst b/en/core-libraries/validation.rst index 92d11eb3df..8906d8c2d1 100644 --- a/en/core-libraries/validation.rst +++ b/en/core-libraries/validation.rst @@ -73,6 +73,26 @@ the mode using the second parameter:: $validator->requirePresence('author_id', 'create'); +If you have multiple fields that are required, you can define them as a list:: + + // Define multiple fields for create + $validator->requirePresence(['author_id', 'title'], 'create'); + + // Define multiple fields for mixed modes + $validator->requirePresence([ + 'author_id' => [ + 'mode' => 'create', + 'message' => 'An author is required.', + ], + 'published' => [ + 'mode' => 'update', + 'message' => 'The published state is required.', + ] + ]); + +.. versionadded:: 3.3.0 + ``requirePresence()`` accepts an array of fields as of 3.3.0 + Allowing Empty Fields ---------------------