Download the PHP package zaruto/queryable without Composer
On this page you can find all versions of the php package zaruto/queryable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package queryable
Laravel Queryable
Attribute-first, type-safe query composition for Laravel Eloquent models.
zaruto/queryable helps API teams safely expose search, filter, and sort query params without allowing arbitrary field/operator access.
Roadmap
Track planned feature waves in GitHub Projects:
- Queryable Roadmap
- In-Repo Backlog
Compatibility
- PHP:
8.3,8.4,8.5 - Laravel:
12.x,13.x
Installation
Publish config (optional):
Quickstart (Under 5 Minutes)
1. Add traits + attributes to a model
2. Chain query scopes in controller/repository
3. Call endpoint with query params
Public API (Stable Surface)
scopeSearch(Builder $query, ?string $search): BuilderscopeFilter(Builder $query): BuilderapplyFilters(Builder $query, Request $request): BuilderscopeSort(Builder $query, ?string $sortBy = null, string $direction = 'asc'): Builder
Configuration
config/queryable.php:
Notes
strict_mode=truevalidates filter fields/operators against your allowlist.- If you rename parameter keys, use the same keys in your clients.
Attribute-First With Method Fallback
The package resolves model config in this order:
- Attributes (
#[QueryableSearchable],#[QueryableFilterable],#[QueryableSortable]) - Static methods (
searchable(),filters(),sortable())
Use method fallback when you need dynamic configuration or gradual migration.
Method fallback example
Filter Grammar Reference
Queryable uses a token parser and supports grouped boolean expressions.
Grammar shape
Supported operators
| Operator | Meaning | Example filter snippet |
|---|---|---|
eq |
equals | status eq active |
ne |
not equals | status ne archived |
gt |
greater than | score gt 80 |
gte |
greater or equal | score gte 80 |
lt |
lower than | score lt 80 |
lte |
lower or equal | score lte 80 |
like |
raw SQL like value |
name like ali% |
contains |
%value% |
name contains ali |
starts_with |
value% |
email starts_with admin |
in |
in comma list | status in active,pending |
not in |
not in comma list | status not in blocked,deleted |
Boolean and grouping
andor- Parentheses
(...)
Example:
Query URL Examples
GET /api/customers?filter=status%20eq%20activeGET /api/customers?filter=score%20gte%2050%20and%20score%20lt%2090GET /api/customers?filter=team.name%20like%20Ops%25GET /api/customers?filter=status%20in%20active,pendingGET /api/customers?filter=(status%20eq%20active%20or%20status%20eq%20pending)%20and%20score%20gt%2060
Relation Fields
Use dot notation for relation fields:
- Search:
team.name - Filter:
team.name
Current behavior:
- Filter relation handling splits on first dot (
relation.field). - Search supports nested relation path style via dot notation keys.
Sorting Behavior
- Only allowlisted fields are sortable.
- Direction normalization:
descstaysdesc- any other value becomes
asc
Examples:
GET /api/customers?sort_by=name&direction=ascGET /api/customers?sort_by=created_at&direction=descGET /api/customers?sort_by=id&direction=INVALID-> usesasc
Strict Mode and Errors
When strict_mode=true:
- Unknown filter field throws
InvalidFilterException. - Disallowed operator for an allowed field throws
InvalidFilterException. - Invalid/incomplete syntax throws
InvalidFilterExceptionfrom parser.
Example invalid requests:
filter=unknown eq 1filter=status between active,pending(unsupported operator)filter=(status eq active(missing closing))
End-to-End Example
Testing and Development
CI workflow coverage:
- tests (
.github/workflows/tests.yml) - lint (
.github/workflows/lint.yml) - static analysis (
.github/workflows/static-analysis.yml)
Pre-Tag Release Gate
Run this before creating any new release tag:
This runs, in order:
composer install./vendor/bin/pint --test./vendor/bin/phpstan analyse --error-format=table./vendor/bin/pest --ci
For additional Laravel matrix spot-checks (recommended for release candidates/finals):
This additionally runs sequential checks for:
- Laravel
12.*+ Testbench^10.0 - Laravel
13.*+ Testbench^11.0
Tagging rule: only create/push a tag if the gate passes and the working tree is clean.
Roadmap (Concise)
- Custom operator registration.
- Relation-aware sorting.
- Multi-column sort expressions.
- Request helper/pipeline utilities.
License
MIT
All versions of queryable with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^12.0||^13.0
illuminate/database Version ^12.0||^13.0
illuminate/http Version ^12.0||^13.0