From 39035ec6e4066a3f051455c061b861d4b592c345 Mon Sep 17 00:00:00 2001 From: Marius Date: Wed, 4 Dec 2024 20:54:55 +0200 Subject: [PATCH] bulletproofing forceReplace and forceOffsetUnset macros --- src/Providers/CrudProvider.php | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/Providers/CrudProvider.php b/src/Providers/CrudProvider.php index 6ada25d..55d4050 100644 --- a/src/Providers/CrudProvider.php +++ b/src/Providers/CrudProvider.php @@ -42,17 +42,9 @@ function (...$arguments): Model { Request::macro('forceOffsetUnset', function (string $offset): Request { /** @var Request $this */ - if ($this->json()->has($offset)) { - $this->json()->remove($offset); - } - - if ($this->query->has($offset)) { - $this->query->remove($offset); - } - - if ($this->request->has($offset)) { - $this->request->remove($offset); - } + $this->query->remove($offset); + $this->request->remove($offset); + $this->offsetUnset($offset); return $this; }); @@ -60,17 +52,9 @@ function (...$arguments): Model { Request::macro('forceReplace', function (array $data): Request { /** @var Request $this */ - if ($this->isJson()) { - $this->json()->replace($data); - } - - if ($this->query->count() > 0) { - $this->query->replace($data); - } - - if ($this->request->count() > 0) { - $this->request->replace($data); - } + $this->query->replace(); + $this->request->replace(); + $this->replace($data); return $this; });