Skip to content

Commit 22340ba

Browse files
ThcDelux3soyuka
andauthored
improve DateFilter usage explanation with example (#2164)
Co-authored-by: Antoine Bluchet <[email protected]>
1 parent a70e3bf commit 22340ba

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

laravel/filters.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,38 @@ As shown above the following search filters are available:
101101

102102
The `DateFilter` allows to filter dates with an operator (`eq`, `lt`, `gt`, `lte`, `gte`):
103103

104+
- `eq` - equals (exact match)
105+
- `gt` - greater than (strictly after)
106+
- `gte` - greater than or equal (after or on)
107+
- `lt` - less than (strictly before)
108+
- `lte` - less than or equal (before or on)
109+
- `after` - alias for `gte`
110+
- `before` - alias for `lte`
111+
- `strictly_after` - alias for `gt`
112+
- `strictly_before` - alias for `lt`
113+
114+
Usage Examples
115+
116+
With the `DateFilter` applied, you can now filter dates between 2024-01-01 and 2024-01-31 using these API calls:
117+
118+
**Option 1: Using gte and lte operators**
119+
120+
```http
121+
GET /api/your_entities?createdAt[gte]=2024-01-01&createdAt[lte]=2024-01-31
122+
```
123+
124+
**Option 2: Using after and before operators**
125+
126+
```http
127+
GET /api/your_entities?createdAt[after]=2024-01-01&createdAt[before]=2024-01-31
128+
```
129+
130+
**Option 3: Using strictly_after and strictly_before**
131+
132+
```http
133+
GET /api/your_entities?createdAt[strictly_after]=2023-12-31&createdAt[strictly_before]=2024-02-01
134+
```
135+
104136
```php
105137
// app/Models/Book.php
106138

0 commit comments

Comments
 (0)