Skip to content

Version 2.2.10

Choose a tag to compare

@wimurk wimurk released this 30 Oct 10:55
· 29 commits to main since this release

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 by ApiModel::getFillable()) or relations (as provided by ApiModel::getRelations()).

  • \SingleQuote\LaravelApiResource\Rules\ValidateHasParameter
    This new dedicated rule correctly validates the complex has parameter. 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::defaults method has been updated to use the new ValidateArrayKeys and ValidateHasParameter rules.
  • Validation for where, whereIn, whereNotIn, with, whereRelation, and has is 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