Skip to content

improve DateFilter usage explanation with example #2164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions laravel/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,38 @@ As shown above the following search filters are available:

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

- `eq` - equals (exact match)
- `gt` - greater than (strictly after)
- `gte` - greater than or equal (after or on)
- `lt` - less than (strictly before)
- `lte` - less than or equal (before or on)
- `after` - alias for `gte`
- `before` - alias for `lte`
- `strictly_after` - alias for `gt`
- `strictly_before` - alias for `lt`

Usage Examples

With the `DateFilter` applied, you can now filter dates between 2024-01-01 and 2024-01-31 using these API calls:

**Option 1: Using gte and lte operators**

```http
GET /api/your_entities?createdAt[gte]=2024-01-01&createdAt[lte]=2024-01-31
```

**Option 2: Using after and before operators**

```http
GET /api/your_entities?createdAt[after]=2024-01-01&createdAt[before]=2024-01-31
```

**Option 3: Using strictly_after and strictly_before**

```http
GET /api/your_entities?createdAt[strictly_after]=2023-12-31&createdAt[strictly_before]=2024-02-01
```

```php
// app/Models/Book.php

Expand Down