Skip to content

Commit 4d23ed6

Browse files
committed
Update docs
1 parent e31707a commit 4d23ed6

File tree

3 files changed

+4
-129
lines changed

3 files changed

+4
-129
lines changed

docs/filters/applying-filters.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ If you don't want to apply at the filter level, you can apply the filter at the
3535
public function builder(): Builder
3636
{
3737
return User::query();
38-
->when($this->getAppliedFilter('active'), fn($query, $active) => $query->where('active', $active === 'yes'));
38+
->when($this->getAppliedFilterWithValue('active'), fn($query, $active) => $query->where('active', $active === 'yes'));
3939
}
4040
```
4141

42-
You can use the `getAppliedFilter()` method to grab the current value of the filter or null if it is not applied.
42+
You can use the `getAppliedFilterWithValue()` method to grab the current value of the filter or null if it is not applied.
4343

4444
### A note about integer values
4545

4646
Even if you have your values as strings, but are still using integers, you may have unexpected results when using Eloquent's `when()` method to apply your filters (if going that route).
4747

4848
For example, if you have values of `0 and 1`, the eloquent `when()` method will not execute when the value is '0' as it treats it as false.
4949

50-
So it is better to not use `getAppliedFilter()` or `integer keys` in the situations where you want to apply the filter in the builder method.
50+
So it is better to not use `getAppliedFilterWithValue()` or `integer keys` in the situations where you want to apply the filter in the builder method.

docs/upgrade-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ $this->getFilter('active');
5353
New:
5454

5555
```php
56-
$this->getAppliedFilter('active');
56+
$this->getAppliedFilterWithValue('active');
5757
```

src/Traits/Helpers/FilterHelpers.php

Lines changed: 0 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -8,153 +8,78 @@
88

99
trait FilterHelpers
1010
{
11-
/**
12-
* @param string $column
13-
* @param string $value
14-
* @return array
15-
*/
1611
public function getFiltersStatus(): bool
1712
{
1813
return $this->filtersStatus;
1914
}
2015

21-
/**
22-
* @param string $column
23-
* @param string $value
24-
* @return array
25-
*/
2616
public function filtersAreEnabled(): bool
2717
{
2818
return $this->getFiltersStatus() === true;
2919
}
3020

31-
/**
32-
* @param string $column
33-
* @param string $value
34-
* @return array
35-
*/
3621
public function filtersAreDisabled(): bool
3722
{
3823
return $this->getFiltersStatus() === false;
3924
}
4025

41-
/**
42-
* @param string $column
43-
* @param string $value
44-
* @return array
45-
*/
4626
public function getFiltersVisibilityStatus(): bool
4727
{
4828
return $this->filtersVisibilityStatus;
4929
}
5030

51-
/**
52-
* @param string $column
53-
* @param string $value
54-
* @return array
55-
*/
5631
public function filtersVisibilityIsEnabled(): bool
5732
{
5833
return $this->getFiltersVisibilityStatus() === true;
5934
}
6035

61-
/**
62-
* @param string $column
63-
* @param string $value
64-
* @return array
65-
*/
6636
public function filtersVisibilityIsDisabled(): bool
6737
{
6838
return $this->getFiltersVisibilityStatus() === false;
6939
}
7040

71-
/**
72-
* @param string $column
73-
* @param string $value
74-
* @return array
75-
*/
7641
public function getFilterPillsStatus(): bool
7742
{
7843
return $this->filterPillsStatus;
7944
}
8045

81-
/**
82-
* @param string $column
83-
* @param string $value
84-
* @return array
85-
*/
8646
public function filterPillsAreEnabled(): bool
8747
{
8848
return $this->getFilterPillsStatus() === true;
8949
}
9050

91-
/**
92-
* @param string $column
93-
* @param string $value
94-
* @return array
95-
*/
9651
public function filterPillsAreDisabled(): bool
9752
{
9853
return $this->getFilterPillsStatus() === false;
9954
}
10055

101-
/**
102-
* @param string $column
103-
* @param string $value
104-
* @return array
105-
*/
10656
public function hasFilters(): bool
10757
{
10858
return $this->getFilters()->count();
10959
}
11060

111-
/**
112-
* @param string $column
113-
* @param string $value
114-
* @return array
115-
*/
11661
public function getFilters(): Collection
11762
{
11863
return collect($this->filters());
11964
}
12065

121-
/**
122-
* @param string $column
123-
* @param string $value
124-
* @return array
125-
*/
12666
public function getFiltersCount(): int
12767
{
12868
return $this->getFilters()->count();
12969
}
13070

131-
/**
132-
* @param string $column
133-
* @param string $value
134-
* @return array
135-
*/
13671
public function getFilterByKey(string $key)
13772
{
13873
return $this->getFilters()->first(function ($filter) use ($key) {
13974
return $filter->getKey() === $key;
14075
});
14176
}
14277

143-
/**
144-
* @param string $column
145-
* @param string $value
146-
* @return array
147-
*/
14878
public function setFilter(string $filterKey, $value)
14979
{
15080
return $this->{$this->getTableName()}['filters'][$filterKey] = $value;
15181
}
15282

153-
/**
154-
* @param string $column
155-
* @param string $value
156-
* @return array
157-
*/
15883
public function selectAllFilterOptions(string $filterKey): void
15984
{
16085
$filter = $this->getFilterByKey($filterKey);
@@ -172,75 +97,40 @@ public function selectAllFilterOptions(string $filterKey): void
17297
$this->setFilter($filterKey, array_keys($filter->getOptions()));
17398
}
17499

175-
/**
176-
* @param string $column
177-
* @param string $value
178-
* @return array
179-
*/
180100
public function setFilterDefaults(): void
181101
{
182102
foreach ($this->getFilters() as $filter) {
183103
$this->resetFilter($filter);
184104
}
185105
}
186106

187-
/**
188-
* @param string $column
189-
* @param string $value
190-
* @return array
191-
*/
192107
public function getAppliedFilters(): array
193108
{
194109
return $this->{$this->getTableName()}['filters'] ?? [];
195110
}
196111

197-
/**
198-
* @param string $column
199-
* @param string $value
200-
* @return array
201-
*/
202112
public function hasAppliedFiltersWithValues(): bool
203113
{
204114
return count($this->getAppliedFiltersWithValues());
205115
}
206116

207-
/**
208-
* @param string $column
209-
* @param string $value
210-
* @return array
211-
*/
212117
public function getAppliedFiltersWithValues(): array
213118
{
214119
return array_filter($this->getAppliedFilters(), function ($item) {
215120
return is_array($item) ? count($item) : $item !== null;
216121
});
217122
}
218123

219-
/**
220-
* @param string $column
221-
* @param string $value
222-
* @return array
223-
*/
224124
public function getAppliedFilterWithValue(string $filterKey)
225125
{
226126
return $this->getAppliedFiltersWithValues()[$filterKey] ?? null;
227127
}
228128

229-
/**
230-
* @param string $column
231-
* @param string $value
232-
* @return array
233-
*/
234129
public function getAppliedFiltersWithValuesCount(): int
235130
{
236131
return count($this->getAppliedFiltersWithValues());
237132
}
238133

239-
/**
240-
* @param string $column
241-
* @param string $value
242-
* @return array
243-
*/
244134
public function resetFilter($filter): void
245135
{
246136
if (! $filter instanceof Filter) {
@@ -250,31 +140,16 @@ public function resetFilter($filter): void
250140
$this->setFilter($filter->getKey(), $filter->getDefaultValue());
251141
}
252142

253-
/**
254-
* @param string $column
255-
* @param string $value
256-
* @return array
257-
*/
258143
public function getFilterLayout(): string
259144
{
260145
return $this->filterLayout;
261146
}
262147

263-
/**
264-
* @param string $column
265-
* @param string $value
266-
* @return array
267-
*/
268148
public function isFilterLayoutPopover(): bool
269149
{
270150
return $this->getFilterLayout() === 'popover';
271151
}
272152

273-
/**
274-
* @param string $column
275-
* @param string $value
276-
* @return array
277-
*/
278153
public function isFilterLayoutSlideDown(): bool
279154
{
280155
return $this->getFilterLayout() === 'slide-down';

0 commit comments

Comments
 (0)