diff --git a/src/Modifiers/CoreModifiers.php b/src/Modifiers/CoreModifiers.php index 36f9ff6bf0..0502f4bf82 100644 --- a/src/Modifiers/CoreModifiers.php +++ b/src/Modifiers/CoreModifiers.php @@ -2549,6 +2549,16 @@ public function toJson($value, $params) return json_encode($value, $options); } + /** + * Converts the data to a query string. + * + * @return string + */ + public function toQs($value) + { + return Arr::query($value); + } + /** * Converts each tab in the string to some number of spaces, as defined by * $param[0]. By default, each tab is converted to 4 consecutive spaces. diff --git a/tests/Modifiers/ToQsTest.php b/tests/Modifiers/ToQsTest.php new file mode 100644 index 0000000000..d066d6e4bf --- /dev/null +++ b/tests/Modifiers/ToQsTest.php @@ -0,0 +1,37 @@ + 'plaid', + 'area' => [51, 52], + 'hat' => null, + 'transportation' => [ + 'bike' => true, + 'delorian' => false, + ], + ]; + $modified = $this->modify(value($input)); + + $expected = 'mode=plaid&area%5B0%5D=51&area%5B1%5D=52&transportation%5Bbike%5D=1&transportation%5Bdelorian%5D=0'; + $this->assertEquals($expected, $modified); + } + + private function modify($value, $options = []) + { + return Modify::value($value)->toQs($options)->fetch(); + } +}