Skip to content

Commit 81eb391

Browse files
Merge pull request #100 from ACT-Training/bugfix/html-safe-filter-codes
Fix date filters broken by Blade HTML-encoding
2 parents 4ac149b + e136487 commit 81eb391

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)