laravel-query-builder

Build Laravel API endpoints with dynamic filtering, sorting, and includes.

113|135|Updated Aug 28, 2019
One-click install
npx skills add https://github.com/hexlet-volunteers/hexlet-sicp --skill laravel-query-builder-hexlet-volunteers
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-query-builder
Source: https://github.com/hexlet-volunteers/hexlet-sicp/tree/main/.agents/skills/laravel-query-builder
Command: npx skills add https://github.com/hexlet-volunteers/hexlet-sicp --skill laravel-query-builder-hexlet-volunteers

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Building flexible Laravel APIs that support dynamic filtering, sorting, and inclusion of related resources without writing repetitive query logic.

Core Features & Use Cases

  • Supports allowed filters, sorts, includes, and fields for Laravel API endpoints
  • Provides easy integration with spatie/laravel-query-builder for complex query scenarios
  • Useful for building resource controllers that need predictable, validated query parameters

Quick Start

Create a scalable API endpoint by enabling filtering, sorting, and includes for a Laravel model using QueryBuilder.

Frequently Asked Questions about laravel-query-builder

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

FAQPage Schema
How do I add dynamic filtering and sorting to Laravel API endpoints?

Dynamic filtering and sorting for Laravel API endpoints is configured using Spatie's Laravel Query Builder. It applies AllowedFilter and AllowedSort to validate query parameters and return filtered model collections without repetitive logic.

What is the best way to include related resources in Laravel RESTful API responses?

Including related resources in Laravel RESTful APIs is handled dynamically via AllowedInclude. It safely parses relationship query parameters to eager-load associated model data, preventing manual join logic and N+1 query issues.

Can I use Spatie Laravel Query Builder for optional field selection in APIs?

Spatie Laravel Query Builder supports optional field selection for APIs. It allows clients to request specific model attributes via query parameters, returning constrained data sets while maintaining validated, predictable endpoint responses.

Does Laravel Query Builder work with complex query scenarios for resource controllers?

Laravel Query Builder integrates with resource controllers to handle complex query scenarios. It validates allowed filters, sorts, and includes against defined parameters, ensuring controlled query execution for scalable API endpoints.

Why do I need allowed filters and sorts instead of writing manual Laravel queries?

Allowed filters and sorts replace manual Laravel queries by validating dynamic API request parameters. This prevents unpredictable query execution, secures endpoints against unauthorized field access, and eliminates repetitive query logic across multiple controllers.