Skip to the content.

Available Model Methods

The victormgomes/laravel-query-engine package automatically equips all Eloquent models with a set of powerful methods. These methods handle everything from query construction to pagination and schema exportation.

Primary Query Methods

paginateQuery(?Request $request = null)

Returns: \Illuminate\Contracts\Pagination\LengthAwarePaginator

This is the most common method you will use. It applies the entire pipeline—filters, sorts, includes, and sparse fieldsets—and returns a standard paginated result. If no $request is passed, it uses the current global request.

public function index(IndexUserRequest $request)
{
    return User::paginateQuery($request);
}

cursorPaginateQuery(?Request $request = null)

Returns: \Illuminate\Contracts\Pagination\CursorPaginator

For massive datasets where offset-based pagination becomes slow, use this method. It applies the same pipeline but returns a cursor-paginated result.

public function index(IndexUserRequest $request)
{
    return User::cursorPaginateQuery($request);
}

buildQuery(?Request $request = null)

Returns: \Illuminate\Database\Eloquent\Builder

If you need to chain additional, hardcoded constraints before executing the pagination, use buildQuery(). This returns the query builder instance with all URL constraints already applied.

public function index(IndexUserRequest $request)
{
    $query = User::buildQuery($request);

    // Add custom, non-URL constraints
    $query->where('is_banned', false);

    return $query->paginate($request->query('page.limit', 15));
}

Introspection & Frontend Support Methods

The package also exposes methods that let you introspect the generated schemas, which is incredibly useful for generating dynamic UIs or OpenAPI documentation.

getQueryRules()

Returns: array

Returns the Laravel validation rules array automatically generated by inspecting the model’s database schema and #[QueryOptions] attributes.

$rules = User::getQueryRules();
// ['filters.name.like' => 'sometimes|string|max:255', ...]

getFilterSchema()

Returns: array

Returns a clean, deduplicated schema representing the allowed filters, sorts, and includes for this model. This is designed specifically for frontend applications to consume so they know exactly what controls to render to the user.

$schema = User::getFilterSchema();
// ['filters' => ['name', 'status'], 'sorts' => ['created_at'], 'includes' => ['posts']]