Skip to content

Commit 117271b

Browse files
Merge pull request #24 from devaction-labs/feat/new-filter
Feat/new filter
2 parents 9841a74 + e2b75f0 commit 117271b

File tree

8 files changed

+1456
-558
lines changed

8 files changed

+1456
-558
lines changed

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,42 @@
22

33
All notable changes to `filterable-package` will be documented in this file.
44

5+
## 1.1.0 - 2025-09-14
6+
7+
### Added
8+
- **New Filter Types**: Added 7 new commonly used filter types
9+
- `ilike()` - Case-insensitive LIKE with database-specific handling (PostgreSQL ILIKE, SQLite LIKE, MySQL LOWER())
10+
- `notEquals()` - NOT EQUALS (!=) filter for excluding specific values
11+
- `notIn()` - NOT IN filter for excluding multiple values from a list
12+
- `notLike()` - NOT LIKE filter for excluding text patterns
13+
- `isNull()` - IS NULL filter for checking null values
14+
- `isNotNull()` - IS NOT NULL filter for checking non-null values
15+
- `startsWith()` - STARTS WITH filter using LIKE with % suffix
16+
- `endsWith()` - ENDS WITH filter using LIKE with % prefix
17+
18+
### Enhanced
19+
- **Database Compatibility**: Improved database-specific handling for different SQL dialects
20+
- PostgreSQL: Uses native ILIKE for case-insensitive searches
21+
- SQLite: Falls back to LIKE for case-insensitive searches
22+
- MySQL: Uses LOWER() function for case-insensitive comparisons
23+
- **Filter Value Processing**: Enhanced `prepareValue()` method to handle new filter types
24+
- Automatic pattern generation for STARTS_WITH and ENDS_WITH
25+
- Support for comma-separated values in NOT_IN filters
26+
- Pattern application for NOT_LIKE filters
27+
28+
### Testing
29+
- **Comprehensive Test Coverage**: Added complete test suite for all new filter types
30+
- Unit tests for each new filter type
31+
- Database driver detection tests
32+
- Operator validation tests
33+
- Integration tests with Filterable trait
34+
35+
### Performance
36+
- **Optimized Query Building**: Enhanced `applyFilterToBuilder()` method
37+
- Direct method calls for null checks (whereNull/whereNotNull)
38+
- Efficient handling of negation filters (whereNotIn)
39+
- Streamlined LIKE pattern processing
40+
541
## 1.0.22 - 2025-04-04
642

743
### Added

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ A Laravel package for filterable traits and classes. This package provides power
1212
## Features
1313

1414
- **Easy Integration:** Apply the `Filterable` trait to your Eloquent models.
15-
- **Flexible Filters:** Exact, like, in, between, greater than (gte, gt), less than (lte, lt), JSON, and relationship filters.
15+
- **Comprehensive Filters:** Support for 15+ filter types including exact, like, ilike, in, between, greater/less than, negation filters (notEquals, notIn, notLike), null checks (isNull, isNotNull), and text pattern filters (startsWith, endsWith).
16+
- **Database Compatibility:** Database-specific optimizations for PostgreSQL, MySQL, and SQLite.
1617
- **Dynamic Sorting:** Customize sorting behavior directly from requests.
1718
- **Relationship Filters:** Use advanced conditional logic like `whereAny`, `whereAll`, and `whereNone` for relational queries.
1819
- **JSON Support:** Directly filter JSON columns with dot-notation.
@@ -84,13 +85,44 @@ class ExpenseController extends Controller
8485
## Available Filters
8586

8687
### Direct Filters
88+
89+
#### Basic Comparison Filters
8790
- **Exact Match:** `Filter::exact('status', 'status')`
88-
- **LIKE Match:** `Filter::like('description', 'search')`
89-
- **IN Clause:** `Filter::in('category_id', 'categories')`
91+
- **Not Equals:** `Filter::notEquals('status', 'exclude_status')`
92+
- **Greater Than:** `Filter::gt('amount', 'min_amount')`
9093
- **Greater Than or Equal:** `Filter::gte('amount', 'min_amount')`
94+
- **Less Than:** `Filter::lt('amount', 'max_amount')`
9195
- **Less Than or Equal:** `Filter::lte('amount', 'max_amount')`
9296
- **Between:** `Filter::between('created_at', 'date_range')`
9397

98+
#### Text Search Filters
99+
- **LIKE Match:** `Filter::like('description', 'search')`
100+
- **Case-Insensitive LIKE:** `Filter::ilike('description', 'search')` **(Database-specific)**
101+
- **NOT LIKE:** `Filter::notLike('description', 'exclude_text')`
102+
- **Starts With:** `Filter::startsWith('name', 'name_prefix')`
103+
- **Ends With:** `Filter::endsWith('email', 'email_suffix')`
104+
105+
#### List and Array Filters
106+
- **IN Clause:** `Filter::in('category_id', 'categories')`
107+
- **NOT IN Clause:** `Filter::notIn('status', 'exclude_statuses')`
108+
109+
#### Null Value Filters
110+
- **Is Null:** `Filter::isNull('deleted_at', 'show_deleted')`
111+
- **Is Not Null:** `Filter::isNotNull('email_verified_at', 'verified_only')`
112+
113+
#### Database-Specific Behavior
114+
The `ilike()` filter automatically adapts to your database:
115+
- **PostgreSQL:** Uses native `ILIKE` operator
116+
- **SQLite:** Falls back to `LIKE` (case-sensitive)
117+
- **MySQL:** Uses `LOWER()` function for case-insensitive comparison
118+
119+
```php
120+
// Example usage for case-insensitive search
121+
$filters = [
122+
Filter::ilike('name', 'search'), // Works across all databases
123+
];
124+
```
125+
94126
### JSON Filters
95127
- **Exact Match:** `Filter::json('data', 'user.name', '=', 'user_name')`
96128
- **LIKE Match:** `Filter::json('data', 'user.name', 'LIKE', 'user_name')`

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"email": "alex@devaction.com.br"
1010
}
1111
],
12-
"version": "1.0.23",
12+
"version": "1.0.24",
1313
"require": {
1414
"php": "^8.2|^8.3|^8.4",
1515
"illuminate/cache": "^11|^12",

0 commit comments

Comments
 (0)