一键导入
laravel-query-engine
A schema-aware API filtering engine for Laravel that handles complex query parameters using native Laravel validation and Eloquent queries.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
A schema-aware API filtering engine for Laravel that handles complex query parameters using native Laravel validation and Eloquent queries.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | laravel-query-engine |
| description | A schema-aware API filtering engine for Laravel that handles complex query parameters using native Laravel validation and Eloquent queries. |
A powerful, schema-aware API filtering engine for Laravel. It handles complex query parameters (filtering, sorting, field selection, relationship loading, and pagination) using native Laravel validation and highly optimized, database-agnostic Eloquent queries. Natively supports MySQL, PostgreSQL, SQLite, and SQL Server.
First, map the FormRequest to its target Model using the MapQueryEngine attribute and use the HasQueryEngineRules trait.
use Illuminate\Foundation\Http\FormRequest;
use Victormgomes\LaravelQueryEngine\Attributes\MapQueryEngine;
use Victormgomes\LaravelQueryEngine\Traits\HasQueryEngineRules;
use App\Models\User;
#[MapQueryEngine(User::class)]
class IndexUserRequest extends FormRequest
{
use HasQueryEngineRules;
public function authorize(): bool
{
return true;
}
}
It generates the validation rules based on the model schema.
// app/Http/Controllers/UserController.php
use Illuminate\Pagination\LengthAwarePaginator;
public function index(IndexUserRequest $request): LengthAwarePaginator
{
// Pass the request to apply all URL parameters inside Controllers, Services, etc.
return User::paginateQuery($request);
}
| Method | Returns | Use case |
|---|---|---|
Model::paginateQuery($r) | LengthAwarePaginator | Full pipeline — filters, sorts, includes, pagination |
Model::cursorPaginateQuery($r) | CursorPaginator | Full pipeline — cursor pagination (massive datasets) |
Model::buildQuery($r) | Eloquent\Builder | Query before pagination — chain custom constraints |
Model::getQueryRules() | array | Validation rules for the model |
Model::getFilterSchema() | array | Deduplicated frontend schema |
(Omitting $request uses the current request natively. IDE Autocompletion
works out of the box).
The package supports two URL formats.
1. JSON Syntax: ?filters={"name":{"like":"John"},"status":"active"}
?sorts={"created_at":"desc"} ?includes={"posts":{"fields":["id","title"]}}
2. Array Syntax: ?filters[name][like]=John ?sorts[created_at]=desc
?includes[posts][fields]=id,title
If you need to implement complex features (such as Local Scopes, Accessors,
Aggregations via #[QueryOptions], specific Date/FTS operators, or rule
interception), please consult the official package documentation and source code
to ensure accurate implementation.
You can view the full documentation and code in the vendor directory:
vendor/victormgomes/laravel-query-engine/docs/vendor/victormgomes/laravel-query-engine/src/