Skip to content

fix: mergeIfMissing function:#198

Merged
techmahedy merged 2 commits intodoppar:3.xfrom
techmahedy:techmahedy-3.x
Feb 25, 2026
Merged

fix: mergeIfMissing function:#198
techmahedy merged 2 commits intodoppar:3.xfrom
techmahedy:techmahedy-3.x

Conversation

@techmahedy
Copy link
Member

Problem

When using mergeIfMissing() (or any method that internally calls has() or input() before mutating request data), the local $this->input cache gets populated and locked. Any subsequent merge into the underlying InputBag is invisible to input(), has(), and the __get() magic method because they all read from the stale cache.

Minimal reproduction:

$request->mergeIfMissing(['test' => 'doppar']);

$request->all();   // returns merged data (reads directly from InputBag)
$request->test;    // returns null (reads from stale cache)
$request->input('test'); // returns `null`
$request->has('test');   // returns `false`

input() and has() in RequestHelper lazily populate $this->input on first access and never invalidate it:

Fix

Invalidate $this->input cache inside merge() so any subsequent read re-fetches fresh data from the underlying InputBag:

public function merge(array $input): self
{
    $this->request->replace(array_merge($this->request->all(), $input));
    $this->input = []; // invalidate stale cache

    return $this;
}

Also fixed

public function nullifyBlanks(...): static
{
    // ...existing logic...
    $this->request->replace($data);
    $this->input = []; // invalidate stale cache

    return $this;
}

The targeted invalidation approach is the minimal, lowest-risk fix — it preserves the intended optimization while correcting the staleness bug.

@techmahedy techmahedy merged commit 449a7ac into doppar:3.x Feb 25, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant