Skip to content
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

Having a second key in the query parameters is not handled by the WritingUtils #533

Closed
Mina-R-Meshriky opened this issue Oct 12, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@Mina-R-Meshriky
Copy link

In Jsonapi we can have query parameters that look like filter[createdAt][lt]=2022-10-12 with

$rules = [
   'filter' => ['array'],
   'filter.createdAt' => ['array:lt,lte,gt,gte,bt'],
   'filter.createdAt.*' => ['date_format:Y-m-d']
];

the following lines are from the WritingUtils.php file

// Hash query param (eg filter[name]=john should become "filter[name]": "john")
foreach ($value as $item => $itemValue) {
$output .= str_repeat(" ", $spacesIndentation);
$output .= "$startLinesWith$quote$parameter" . "[$item]$quote$delimiter $quote$itemValue$quote$endLinesWith\n";

to handle the above scenario it can be changed to:

// Hash query param (eg filter[name]=john should become "filter[name]": "john")
                    foreach ($value as $item => $itemValue) {
                        $output .= str_repeat(" ", $spacesIndentation);
                        if(is_array($itemValue)) {
                            $key = array_key_first($itemValue);
                            $itemValue = $itemValue[$key];
                            $output .= "$startLinesWith$quote$parameter" . "[$item][$key]$quote$delimiter $quote$itemValue$quote$endLinesWith\n";
                        } else {
                            $output .= "$startLinesWith$quote$parameter" . "[$item]$quote$delimiter $quote$itemValue$quote$endLinesWith\n";
                        }
                    }
@Mina-R-Meshriky
Copy link
Author

its worth noting that I use formRequests for query parameters.

@shalvah
Copy link
Contributor

shalvah commented Oct 15, 2022

I see your point, and it's doable, but I find it somewhat iffy, because I'm wondering what happens if we have another level of nesting? Can quickly turn into a recursive mess. I'll probably implement this, but I generally advise against using arrays in query parameters.

@shalvah shalvah added the enhancement New feature or request label Oct 15, 2022
@shalvah
Copy link
Contributor

shalvah commented Jan 15, 2023

I think this is fixed now, by #603

@shalvah shalvah closed this as completed Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants