File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,32 @@ public function __construct(string $property, $value)
1515
1616 public function asArray (): array
1717 {
18+ // Remove individual value from array
19+ // new ArrayPull("list", "user.123")
20+ if (!is_array ($ this ->value )) {
21+ return [
22+ "\$pull " => [
23+ $ this ->name => $ this ->value
24+ ]
25+ ];
26+ }
27+
28+ // Remove array values from property
29+ // new ArrayPull("list", ["user.123", "user.456"])
30+ if (is_int (array_keys ($ this ->value )[0 ])) {
31+ return [
32+ "\$pull " => [
33+ $ this ->name => [
34+ "\$in " => $ this ->value
35+ ]
36+ ]
37+ ];
38+ }
39+
40+ // Remove objects from array with conditions
41+ // new ArrayPull("list", ["id" => ["user.123", "user.456"]])
42+ // new ArrayPull("list", ["id" => "user.123"])
43+ // new ArrayPull("list", ["id" => "user.123", "name" => "joe"])
1844 foreach ($ this ->value as $ key => &$ value ) {
1945 if (is_array ($ value )) {
2046 $ value = [
You can’t perform that action at this time.
0 commit comments