Skip to content

Add relations validation in GetRequest and SearchRequest #206

@DenTray

Description

@DenTray

Description


What needs to be done?


In the request classes GetRequest and SearchRequest , add validation for the specified relations using the rule pattern:

$availableRelations = implode(',', $this->getAvailableRelations());

'with.*' => 'required|string|in:' . $availableRelations

Implement the protected method getAvailableRelations() that returns an array of allowed relations provided.
Add the comment before this method:

// TODO: don't forget to review relations list

Expected Outcome


What is the expected result?


The requests will validate the with relations parameter correctly, only allowing those specified in getAvailableRelations() . This prevents invalid relations from passing validation and ensures consistent relation handling.

Verification Scenarios


How can this be tested?


  • Test requests with valid relations such as role included in with and confirm they pass validation.

  • Test requests with invalid or missing relations in with and confirm validation errors are returned.

  • Confirm the getAvailableRelations() method is present and preceded by the specified TODO comment.

  • Ensure no errors or warnings occur related to relations validation.


Resources


Materials

Example of using the with field check: https://github.com/RonasIT/laravel-empty-project/blob/development/app/Http/Requests/Users/SearchUserRequest.php

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions