Skip to content

Commit 7bb74ad

Browse files
Merge pull request #3 from CodeWithDennis/2-feature-price-filter-slider
Add price filter slider component and settings
2 parents a46de23 + 7201dbc commit 7bb74ad

File tree

11 files changed

+3745
-65
lines changed

11 files changed

+3745
-65
lines changed

README.md

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ You can install the package via composer:
1616
composer require codewithdennis/filament-price-filter
1717
```
1818

19+
Make sure you add the following to your `tailwind.config.js` file. You will need to create a [theme](https://filamentphp.com/docs/3.x/panels/themes#creating-a-custom-theme) if you haven't already.
20+
21+
```js
22+
'./vendor/codewithdennis/filament-price-filter/resources/**/*.blade.php'
23+
```
24+
1925
You can publish the config file with:
2026

2127
```bash
@@ -30,40 +36,80 @@ This is the contents of the published config file:
3036
return [
3137
'currency' => 'USD',
3238
'cents' => true,
33-
'column' => 'price'
3439
];
3540
```
3641

3742
## Usage
38-
39-
By default, the column that the filter will use is `price`, but you can change it to any column you want.
40-
41-
```php
42-
PriceFilter::make()
43-
->currency(column: 'total_price')
44-
```
43+
> [!NOTE]
44+
> Global settings can be overridden by passing the desired values to the `PriceFilter::make('price')` method.
4545
4646
By default, the currency is set to USD globally, but you can change it per filter to any currency you want.
4747

4848
```php
49-
PriceFilter::make()
49+
PriceFilter::make('price')
5050
->currency(currency: 'EUR')
5151
```
5252

5353
The filter will use the locale that is used in the application `config('app.locale')`, but you can also set a custom locale.
5454

5555
```php
56-
PriceFilter::make()
57-
->currency(currency: 'EUR', locale: 'NL'),
56+
PriceFilter::make('price')
57+
->currency(locale: 'NL'),
5858
```
5959

6060
A good practice is to save your currency as cents but if you saved it as a whole number you can disable the cents.
6161

6262
```php
63-
PriceFilter::make()
64-
->currency(currency: 'EUR', locale: 'NL', cents: false),
63+
PriceFilter::make('price')
64+
->currency(cents: false),
65+
```
66+
67+
If you want to use a range slider instead of an input field you can enable it.
68+
69+
```php
70+
PriceFilter::make('price')
71+
->slider()
72+
```
73+
74+
Set the minimum and maximum values for the filter.
75+
76+
```php
77+
PriceFilter::make('price')
78+
->min(100)
79+
->max(1000)
6580
```
6681

82+
If you want to grab the min, max values from the database you can use the `min` and `max` methods. Here is an example of how you can use it with caching.
83+
84+
> [!NOTE]
85+
> Flexible cache is a caching helper method that is introduced in Laravel 11.23.0, you can also use the default cache function.
86+
87+
```php
88+
->min(fn () => Cache::flexible('min_price', [30, 60], function () {
89+
return Order::min('price') / 100; // Divide by 100 if you saved it as cents
90+
}))
91+
````
92+
93+
```php
94+
->max(fn () => Cache::flexible('max_price', [30, 60], function () {
95+
return Order::max('price') / 100; // Divide by 100 if you saved it as cents
96+
}))
97+
```
98+
The step value is used to determine the interval between each value in the filter.
99+
100+
```php
101+
PriceFilter::make('price')
102+
->step(100)
103+
```
104+
105+
By default, the label will be the name of the filter, for example `PriceFilter::make('total_price')` will have a label of `Total price to` and `Total price from`. You can change the label to whatever you want.
106+
107+
```php
108+
PriceFilter::make('price')
109+
->label('Shipping price')
110+
```
111+
112+
67113
## Changelog
68114

69115
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

config/filament-price-filter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
return [
44
'currency' => 'USD',
55
'cents' => true,
6-
'column' => 'price',
76
];

0 commit comments

Comments
 (0)