0071-laravel-query-builder

Constructs controlled Laravel API queries with configurable filters, sorts, includes, and fields.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/MrJmpl3/codex_____data_____configuration --skill 0071-laravel-query-builder
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: 0071-laravel-query-builder
Source: https://github.com/MrJmpl3/codex_____data_____configuration/tree/main/skills/0071-laravel-query-builder
Command: npx skills add https://github.com/MrJmpl3/codex_____data_____configuration --skill 0071-laravel-query-builder

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Building Laravel API endpoints often leads to repetitive, error-prone code for handling filter, sort, include, and fields query parameters while keeping database queries safe and controlled.

Core Features & Use Cases

  • Allowed filters, sorts, and includes: Define exactly which query parameters the API accepts, including partial/exact/beginsWith/endsWith, scopes, callbacks, relation-based filters, and soft-delete handling.
  • Sorting and default ordering: Support aliases, custom sort logic, callbacks (including random ordering), and sensible defaults.
  • Relationship inclusion and field selection: Enable eager loading via allowedIncludes() and optional aggregated includes (count/exists/min/max/sum/avg), along with allowedFields() for controlled projection.
  • Custom extensibility: Implement custom filter/sort/include classes to match domain-specific query rules.

Quick Start

Configure a Laravel controller index method to build a QueryBuilder::for(User::class) endpoint that allows specific filters, sorts, includes, and allowed fields for requests like filter[name], sort, and include.

Frequently Asked Questions about 0071-laravel-query-builder

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle API filtering and sorting in Laravel safely?

API filtering and sorting in Laravel is handled safely by configuring allowed query parameters, enforcing exact constraints on filters and sorts, and preventing unintended database queries via controlled request validation.

How do I set up eager loading and field selection for a Laravel REST endpoint?

Eager loading and field selection for a Laravel REST endpoint are set up by defining allowed includes and allowed fields, enabling clients to request specific relationship projections and aggregate data safely.

Can I use custom query filters and sorting logic with Spatie QueryBuilder?

You can use custom query filters and sorting logic with Spatie QueryBuilder by implementing custom filter, sort, and include classes that match domain-specific query rules and applying them to the endpoint.

Does Laravel Query Builder support aggregate includes like count and sum?

Laravel Query Builder supports aggregate includes by allowing clients to request count, exists, min, max, sum, and avg aggregates alongside standard relationship eager loading through configured include parameters.

What is the best way to prevent unintended queries in Laravel API endpoints?

The best way to prevent unintended queries in Laravel API endpoints is to strictly configure allowed filters, sorts, includes, and fields, ensuring the API only processes explicitly defined client-driven parameters.