validateRequest method
Run a FormRequest through this mixin's error bag instead of
FormRequest.validate().
FormRequest.validate() filters its return value to the keys declared
in FormRequest.rules and never touches validationErrors, so a
controller calling it directly would neither clear stale errors before
a resubmit, populate per-field errors on failure, nor repaint the form.
validateRequest runs the same authorize/prepare sequence but hands the
prepared payload to this mixin's own validate, which clears,
populates and repaints exactly as a controller-authored rule map would,
and then returns the FULL prepared map (not the rule-filtered one), so a
write path can still send along fields the backend needs but no rule
constrains.
Throws AuthorizationException when FormRequest.authorize returns
false, before any field is touched. Otherwise a ValidationException
propagates after populating validationErrors.
Runs only synchronous Rules: any AsyncRule in request's rules is
skipped (see Validator.validate). Use validateRequestAsync when a
rule needs to await.
Implementation
Map<String, dynamic> validateRequest(
FormRequest request,
Map<String, dynamic> data,
) {
if (!request.authorize()) {
throw const AuthorizationException();
}
final prepared = request.prepared(data);
validate(prepared, request.rules());
return prepared;
}