Skip to content

Commit

Permalink
bulletproofing forceReplace and forceOffsetUnset macros
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius committed Dec 4, 2024
1 parent 16a17cb commit 39035ec
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/Providers/CrudProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,19 @@ 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;
});

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;
});
Expand Down

0 comments on commit 39035ec

Please sign in to comment.