Validating Request bodies

When handling a request we want to easily verify, if our incoming data contains all the stuff we want and only the stuff we want. For this reason, FMVC utilizes the Dry::PHP library to validate request bodies against a predefined model.

For each action defined in routes.php an individual model can be declared.

The basics

At first we need to define a model. Our validation models are being stored in Validation\.

use Dry\DryStruct;
class User extends DryStruct
public function __construct() {

A property can be declared as either required or optional. It is important to declare all optional fields as the validation will point out all additional fields occurring in the used payload, that are not being declared in the model it will validte against.