Skip to content

Commit e136487

Browse files
Fix date filters broken by Blade HTML-encoding of operators
Filter codes containing >= or <= operators were being HTML-encoded by Blade's {{ }} syntax (e.g. >= became &gt;=), causing a mismatch between the Livewire wire:model binding key and the PHP lookup key. This made all date filters with comparison operators silently fail. Operators are now mapped to safe aliases (gte, lte, gt, lt) in the filter code while keeping the actual SQL operator unchanged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4ac149b commit e136487

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

src/Support/Filters/BaseFilter.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct($key, $label)
2121
{
2222
$this->key = $key;
2323
$this->label = $label;
24-
$this->code = $label.':'.$this->operator;
24+
$this->code = $this->buildCode();
2525
}
2626

2727
public static function make($label, $key = null): static
@@ -61,11 +61,30 @@ public function component(): string
6161
public function useOperator(string $operator): static
6262
{
6363
$this->operator = $operator;
64-
$this->code = $this->label.':'.$this->operator;
64+
$this->code = $this->buildCode();
6565

6666
return $this;
6767
}
6868

69+
/**
70+
* Build the filter code from the label and a Blade-safe operator alias.
71+
*
72+
* Operators like >= and <= are mapped to gte/lte so that Blade's {{ }}
73+
* HTML-encoding does not break wire:model bindings.
74+
*/
75+
private function buildCode(): string
76+
{
77+
$operator = match ($this->operator) {
78+
'>=' => 'gte',
79+
'<=' => 'lte',
80+
'>' => 'gt',
81+
'<' => 'lt',
82+
default => $this->operator,
83+
};
84+
85+
return $this->label.':'.$operator;
86+
}
87+
6988
public function useComponent(string $component): static
7089
{
7190
$this->component = $component;

0 commit comments

Comments
 (0)