Repository navigation
Version 2.2.10
Release 2.2.10 - Enhanced API Validation
This release introduces a significant improvement to the API filter validation logic. We've added two new custom rules to provide robust, key-based validation for associative array parameters (like where and with) and dedicated handling for the has parameter.
This makes your API endpoints more secure and provides much clearer, more accurate feedback for invalid query parameters, preventing 500-level database errors and instead returning a 422 validation response.
Added
-
\SingleQuote\LaravelApiResource\Rules\ValidateArrayKeys
This new rule validates that all keys in an associative array (e.g.,where[name]=test) are present in the model's allowed list of attributes (as provided byApiModel::getFillable()) or relations (as provided byApiModel::getRelations()). -
\SingleQuote\LaravelApiResource\Rules\ValidateHasParameter
This new dedicated rule correctly validates the complexhasparameter. It supports both simple list validation (e.g.,has[0]=posts) and associative array key validation (e.g.,has[roles][where]=...), checking all values/keys against the model's relations.
Changed
- The
ApiRequestService::defaultsmethod has been updated to use the newValidateArrayKeysandValidateHasParameterrules. - Validation for
where,whereIn,whereNotIn,with,whereRelation, andhasis now significantly more robust. - API requests using invalid column or relation names in these parameters will now correctly receive a 422 validation response instead of potentially causing a 500-level database error.
Full Changelog: 2.2.9...2.2.10