-
Notifications
You must be signed in to change notification settings - Fork 3
[194]: modify search request #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modifies the search request generation to add enhanced validation for the order_by parameter by constraining it to only accept orderable fields from the corresponding model class.
- Adds model class import to search request templates
- Updates
order_byvalidation rule to include dynamic field validation usingself::getOrderableFields() - Updates test fixtures and template generation logic to support the new validation pattern
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/fixtures/RequestGeneratorTest/search_request.php | Updated search request fixture with model import and enhanced order_by validation |
| tests/fixtures/CommandTest/subfolder/search_request.php | New search request fixture with model-specific validation |
| tests/fixtures/CommandTest/search_request.php | Updated search request fixture with model import and validation |
| tests/CommandTest.php | Updated test to reference correct fixture path |
| stubs/request.blade.php | Enhanced template to conditionally add model import and order_by validation logic |
| src/Generators/RequestsGenerator.php | Added entityNamespace parameter to template data |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
stubs/request.blade.php
Outdated
| @foreach($parameters as $parameter) | ||
| '{{ $parameter['name'] }}' => '{{ implode('|', $parameter['rules']) }}', | ||
| @if($method === $requestsGenerator::SEARCH_METHOD && $parameter['name'] === 'order_by') | ||
| '{{ $parameter['name'] }}' => '{{ implode('|', $parameter['rules']) }}|in:' . self::getOrderableFields({{ Str::singular($entity) }}::class), |
Copilot
AI
Sep 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The validation rule construction concatenates strings in a complex way that could be error-prone. Consider extracting this logic into a helper method or variable for better readability and maintainability.
| '{{ $parameter['name'] }}' => '{{ implode('|', $parameter['rules']) }}|in:' . self::getOrderableFields({{ Str::singular($entity) }}::class), | |
| @php | |
| $orderByRule = implode('|', $parameter['rules']) . '|in:' . self::getOrderableFields({{ Str::singular($entity) }}::class); | |
| @endphp | |
| '{{ $parameter['name'] }}' => '{{ $orderByRule }}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@neellii may we add the in rule in this method
| protected function getRules($name, $type, $required, $nullable, $present): array |
stubs/request.blade.php
Outdated
| @foreach($parameters as $parameter) | ||
| '{{ $parameter['name'] }}' => '{{ implode('|', $parameter['rules']) }}', | ||
| @if($method === $requestsGenerator::SEARCH_METHOD && $parameter['name'] === 'order_by') | ||
| '{{ $parameter['name'] }}' => '{{ implode('|', $parameter['rules']) }}|in:' . self::getOrderableFields({{ Str::singular($entity) }}::class), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@neellii may we add the in rule in this method
| protected function getRules($name, $type, $required, $nullable, $present): array |
tests/CommandTest.php
Outdated
| $this->assertGeneratedFileEquals('create_request.php', 'app/Http/Requests/Post/CreatePostRequest.php'); | ||
| $this->assertGeneratedFileEquals('get_request.php', 'app/Http/Requests/Post/GetPostRequest.php'); | ||
| $this->assertGeneratedFileEquals('search_request.php', 'app/Http/Requests/Post/SearchPostsRequest.php'); | ||
| $this->assertGeneratedFileEquals('subfolder/search_request.php', 'app/Http/Requests/Post/SearchPostsRequest.php'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's strange, could you please investigate the reason of why search request generated in the subfolder?
| 'page' => 'integer', | ||
| 'per_page' => 'integer', | ||
| 'order_by' => 'string', | ||
| 'order_by' => 'string|in:' . self::getOrderableFields(Post::class), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 'order_by' => 'string|in:' . self::getOrderableFields(Post::class), | |
| 'order_by' => 'string|in:' . $this->getOrderableFields(Post::class), |
refs: #194