From a044706db77e2f65d820f6b9ab305a275837348d Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 16 Jul 2021 17:17:54 +0300 Subject: [PATCH] feat(macros): add `onlyFromCollection` and `exceptFromCollection` macros for Arrays #553 --- src/flextype/Support/Macros/Arrays.php | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/flextype/Support/Macros/Arrays.php diff --git a/src/flextype/Support/Macros/Arrays.php b/src/flextype/Support/Macros/Arrays.php new file mode 100644 index 00000000..57ea1a21 --- /dev/null +++ b/src/flextype/Support/Macros/Arrays.php @@ -0,0 +1,39 @@ +toArray() as $key => $value) { + $result[$key] = arrays($value)->only($keys)->toArray(); + } + + return arrays($result); +}); + +Arrays::macro('exceptFromCollection', function(array $keys) { + $result = []; + + foreach ($this->toArray() as $key => $value) { + $result[$key] = arrays($value)->except($keys)->toArray(); + } + + return arrays($result); +}); \ No newline at end of file