Testing Filters
Purpose
The filterable:test command allows you to test and debug filter classes directly from the command line. It applies the specified filter on a given model and displays the resulting SQL query, helping you verify that your filters behave as expected.
Usage
php artisan filterable:test {filter} --model=User --data="status=active,age=30"
Arguments
| Name | Description | Required |
|---|---|---|
filter | The name of the filter class (e.g., UserFilter). It must exist in your configured filter namespace. | ✅ Yes |
Options
| Option | Description | Example |
|---|---|---|
--model | The Eloquent model class to apply the filter on. Defaults to App\Models\{ModelName} if not fully qualified. | --model=User |
--data | A comma-separated list of filter key-value pairs to simulate a filter input. | --data="status=active,age=30" |
Example
php artisan filterable:test UserFilter --model=User --data="status=active,age=30"
Output:
🔍 Testing filter: App\Http\Filters\UserFilter
🧩 Model: App\Models\User
Applied filters:
• status = active
• age = 30
✅ Query:
select * from "users" where "status" = 'active' and "age" = 30;
How It Works
- The command resolves your filter class from the configured namespace (
filterable.filter_namespace). - It instantiates the model and builds an Eloquent query.
- The filter is applied to that query using its
apply()method. - The resulting SQL query is displayed in the console.