Agent skill

Laravel Query Builder

by hexlet-volunteers in hexlet-volunteers/hexlet-sicp

Build filtered, sorted, and included API endpoints using spatie/laravel-query-builder.

MITAuto-check passedBackend & APIs

Install Laravel Query Builder

skills CLI
$ npx skills add hexlet-volunteers/hexlet-sicp --skill laravel-query-builder -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install hexlet-volunteers/hexlet-sicp laravel-query-builder --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/hexlet-volunteers/hexlet-sicp.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/laravel-query-builder .claude/skills/laravel-query-builder && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
laravel-query-builder
GitHub stars
114
Token cost
~2.4k tokens
SKILL.md length
222 words
Files
1
Skills in repo
4
Repo updated
First seen
Licence
MIT

At a glance

Build filtered, sorted, and included API endpoints using spatie/laravel-query-builder.

  • Mentions query parameters
  • SKILL.md covers When to Apply, Basic Usage, Filtering and Sorting, plus 7 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Spatie/laravel-query-builder

What it does

Laravel Query Builder is an agent skill from hexlet-volunteers/hexlet-sicp. Build filtered, sorted, and included API endpoints using spatie/laravel-query-builder. Activates when working with QueryBuilder, AllowedFilter, AllowedSort, AllowedInclude, or when the user mentions query parameters, API filtering, sorting, includes, or spatie/laravel-query-builder.

Its SKILL.md is about 2.4k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Backend & APIs, covering ORMs and data access, Backend development and REST APIs. It works with Laravel. The repository describes itself as: Hexlet SICP is a service for those studying the book Structure and Interpretation of Computer Programs. Track your progress and match yourself against others on the global… The licence is MIT.

When your agent uses it

  • Mentions query parameters
  • Spatie/laravel-query-builder

Example prompts

  • “/laravel-query-builder”

What it can do on your machine

Read from SKILL.md and the folder at commit 4113c36. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are php).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Laravel Query Builder loads about 2.4k tokens when it runs. Until then it costs about 76 tokens; SKILL.md has 222 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~76
When it runs · the whole SKILL.md, loaded when a task matches
~2.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from hexlet-volunteers/hexlet-sicp at commit 4113c36, republished under its MIT licence (© hexlet-volunteers). 222 words, ~2,357 tokens.

Download SKILL.mdSave it as .claude/skills/laravel-query-builder/SKILL.md (or your agent's skills folder).
name
laravel-query-builder
description
Build filtered, sorted, and included API endpoints using spatie/laravel-query-builder. Activates when working with QueryBuilder, AllowedFilter, AllowedSort, AllowedInclude, or when the user mentions query parameters, API filtering, sorting, includes, or spatie/laravel-query-builder.
license
MIT
metadata.author
spatie

Laravel Query Builder

When to Apply

Activate this skill when:

  • Building API endpoints that accept filter, sort, include, or fields query parameters
  • Configuring allowed filters, sorts, includes, or field selections
  • Creating custom filter, sort, or include classes
  • Troubleshooting query builder exceptions or unexpected query results

Basic Usage

php
use Spatie\QueryBuilder\QueryBuilder;
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\AllowedInclude;
use Spatie\QueryBuilder\AllowedSort;

// GET /users?filter[name]=John&sort=-created_at&include=posts
$users = QueryBuilder::for(User::class)
    ->allowedFilters('name', 'email')
    ->allowedSorts('name', 'created_at')
    ->allowedIncludes('posts', 'permissions')
    ->allowedFields('id', 'name', 'email')
    ->get();

Filtering

Filter Types
php
use Spatie\QueryBuilder\AllowedFilter;

QueryBuilder::for(User::class)
    ->allowedFilters(
        AllowedFilter::partial('name'),           // WHERE name LIKE '%value%' (default)
        AllowedFilter::exact('email'),             // WHERE email = 'value'
        AllowedFilter::beginsWith('name'),         // WHERE name LIKE 'value%'
        AllowedFilter::endsWith('name'),           // WHERE name LIKE '%value'
        AllowedFilter::scope('active'),            // Calls scopeActive()
        AllowedFilter::callback('search', fn ($query, $value) => ...),
        AllowedFilter::exact('role')->default('user'),  // Default filter value
        AllowedFilter::exact('status')->nullable(),     // Allows null values
        AllowedFilter::exact('role')->ignore('admin'),  // Ignores specific values
        AllowedFilter::belongsTo('author'),             // Filter by BelongsTo relationship
        AllowedFilter::trashed(),                       // Filter soft deletes (with, only, without)
    );
Operator Filters
php
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\Enums\FilterOperator;

QueryBuilder::for(User::class)
    ->allowedFilters(
        AllowedFilter::operator('salary', FilterOperator::GreaterThan),
        AllowedFilter::operator('age', FilterOperator::LessThanOrEqual),
        AllowedFilter::operator('salary', FilterOperator::Dynamic), // Operator from request
    );

// GET /users?filter[salary]=gt:50000 (with Dynamic operator)
Relation Filters

Filter by related model properties using dot notation:

php
// GET /users?filter[posts.title]=Laravel
QueryBuilder::for(User::class)
    ->allowedFilters(AllowedFilter::partial('posts.title'));
Custom Column Names
php
// GET /users?filter[email]=john
// Queries the 'user_email' column
AllowedFilter::exact('email', 'user_email');
Custom Filters

Implement Spatie\QueryBuilder\Filters\Filter:

php
use Spatie\QueryBuilder\Filters\Filter;
use Illuminate\Database\Eloquent\Builder;

class FiltersUserPermission implements Filter
{
    public function __invoke(Builder $query, mixed $value, string $property): void
    {
        $query->whereHas('permissions', fn ($q) => $q->where('name', $value));
    }
}

AllowedFilter::custom('permission', new FiltersUserPermission());

Sorting

php
use Spatie\QueryBuilder\AllowedSort;
use Spatie\QueryBuilder\Enums\SortDirection;

QueryBuilder::for(User::class)
    ->allowedSorts(
        'name',
        'created_at',
        AllowedSort::field('order', 'sort_order'),   // Alias: ?sort=order queries sort_order
        AllowedSort::custom('popular', new SortMostPopular()),
        AllowedSort::callback('random', fn ($query, $descending) => $query->inRandomOrder()),
    )
    ->defaultSort('name')
    ->defaultSorts('name', AllowedSort::field('date', 'created_at')->defaultDirection(SortDirection::Descending));

// GET /users?sort=-created_at,name (descending created_at, ascending name)
Custom Sorts

Implement Spatie\QueryBuilder\Sorts\Sort:

php
use Spatie\QueryBuilder\Sorts\Sort;
use Illuminate\Database\Eloquent\Builder;
use Spatie\QueryBuilder\Enums\SortDirection;

class SortMostPopular implements Sort
{
    public function __invoke(Builder $query, SortDirection $direction, string $property): void
    {
        $query->withCount('followers')->orderBy('followers_count', $direction->value);
    }
}

Including Relationships

php
use Spatie\QueryBuilder\AllowedInclude;

QueryBuilder::for(User::class)
    ->allowedIncludes(
        'posts',                                     // Eager loads posts (also allows postsCount and postsExists)
        'posts.comments',                            // Nested eager loading
        AllowedInclude::count('commentsCount'),      // Only withCount, no full relation
        AllowedInclude::exists('postsExists'),       // Only withExists
        AllowedInclude::relationship('profile', 'userProfile'), // Alias
        AllowedInclude::callback('latestPost', fn ($query) => $query->latestOfMany()),
    );

// GET /users?include=posts,commentsCount,postsExists
Aggregate Includes
php
AllowedInclude::min('postsViewsMin', 'posts', 'views');   // withMin('posts', 'views')
AllowedInclude::max('postsViewsMax', 'posts', 'views');   // withMax('posts', 'views')
AllowedInclude::sum('postsViewsSum', 'posts', 'views');   // withSum('posts', 'views')
AllowedInclude::avg('postsViewsAvg', 'posts', 'views');   // withAvg('posts', 'views')

// GET /users?include=postsViewsSum,postsViewsAvg
Custom Includes

Implement Spatie\QueryBuilder\Includes\IncludeInterface:

php
use Spatie\QueryBuilder\Includes\IncludeInterface;
use Illuminate\Database\Eloquent\Builder;

class IncludeLatestPost implements IncludeInterface
{
    public function __invoke(Builder $query, string $include): void
    {
        $query->with(['latestPost' => fn ($q) => $q->latest()]);
    }
}

AllowedInclude::custom('latestPost', new IncludeLatestPost());

Field Selection

php
// GET /users?fields[users]=id,name&fields[posts]=id,title&include=posts
QueryBuilder::for(User::class)
    ->allowedFields('id', 'name', 'email')
    ->allowedIncludes('posts')
    ->get();

Configuration

Published to config/query-builder.php:

php
return [
    // Custom query parameter names
    'parameters' => [
        'include' => 'include',
        'filter' => 'filter',
        'sort' => 'sort',
        'fields' => 'fields',
    ],

    // Array value delimiter
    'delimiter' => ',',

    // Include suffixes (for count, exists, and aggregate includes)
    'suffixes' => [
        'count' => 'Count',
        'exists' => 'Exists',
        'min' => 'Min',
        'max' => 'Max',
        'sum' => 'Sum',
        'avg' => 'Avg',
    ],

    // Disable exception throwing for invalid queries
    'disable_invalid_filter_query_exception' => false,
    'disable_invalid_sort_query_exception' => false,
    'disable_invalid_include_query_exception' => false,
];

Wildcard Allow-All

Allow any requested filter, sort, or include without explicit listing. Restricted to local and testing environments:

php
QueryBuilder::for(User::class)
    ->allowedFilters('*')
    ->allowedSorts('*')
    ->allowedIncludes('*');

Starting from Existing Queries

php
// From an Eloquent query
QueryBuilder::for(User::where('active', true))
    ->allowedFilters('name')
    ->get();

// From a relation
QueryBuilder::for($team->users())
    ->allowedFilters('name')
    ->get();

Common Patterns

Controller with Full Query Builder
php
class UsersController
{
    public function index()
    {
        $users = QueryBuilder::for(User::class)
            ->allowedFilters(
                AllowedFilter::partial('name'),
                AllowedFilter::exact('email'),
                AllowedFilter::scope('active'),
            )
            ->allowedSorts('name', 'created_at')
            ->allowedIncludes('posts', 'permissions')
            ->allowedFields('id', 'name', 'email')
            ->defaultSort('name')
            ->paginate();

        return UserResource::collection($users);
    }
}
Dynamic Arrays with Variadic Methods
php
$filters = ['name', 'email'];
$sorts = ['name', 'created_at'];

QueryBuilder::for(User::class)
    ->allowedFilters(...$filters)
    ->allowedSorts(...$sorts);

Common Pitfalls

  • N+1 queries: Always use allowedIncludes() to eager load relationships instead of accessing them in views/resources without loading
  • Forgetting to allow: All filters, sorts, includes, and fields must be explicitly allowed. Unallowed parameters throw exceptions by default
  • Filter value types: Filter values come from query strings as strings. Use AllowedFilter::exact() for boolean/integer columns, or handle casting in custom filters
  • Nested include counts: Count and exists variants are only auto-generated for top-level includes, not for nested includes like posts.comments
  • Field selection with includes: When using allowedFields() with allowedIncludes(), make sure to include the foreign key columns needed for the relationships

© hexlet-volunteers, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/laravel-query-builder of hexlet-volunteers/hexlet-sicp.

Open the folder on GitHubat commit 4113c36

Compare with similar skills

Laravel Query Builder next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Laravel Query Builder compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Laravel Query Builder this skillhexlet-volunteers/hexlet-sicp114—~2.4kAutomated safety check: PassMIT
Laravel SpecialistJeffallan/claude-skills12k1 repos~2.1kAutomated safety check: PassMIT
Fastcrudbenavlabs/fastcrud1.6k—~5kAutomated safety check: PassMIT
Grails Developer Guideapache/grails-core2.9k—~4.9kAutomated safety check: PassApache-2.0
C# and .NET DeveloperJeffallan/claude-skills12k—~1.3kAutomated safety check: PassMIT
Django ExpertJeffallan/claude-skills12k—~1.5kAutomated safety check: PassMIT

Similar skills

  • Laravel Specialist

    Jeffallan/claude-skills

    Builds Laravel 10+ applications with Eloquent models, Sanctum authentication, Horizon queues, API resources and Livewire components, tested with Pest or PHPUnit.

    12k GitHub starsUsed in 1 repo~2.1k tokens
    Backend & APIsAuto-check passed
  • Fastcrud

    benavlabs/fastcrud

    A skill your agent uses when building or modifying CRUD endpoints with FastCRUD (the fastcrud PyPI package) in a FastAPI project — covers FastCRUD, crudrouter, EndpointCreator, FilterConfig…

    1.6k GitHub stars~5k tokensUpdated today
    Backend & APIsAuto-check passed
  • Grails Developer Guide

    apache/grails-core

    Guides building Grails web applications and REST APIs with GORM, controllers, services, views, plugins and Spock and Geb testing.

    2.9k GitHub stars~4.9k tokensUpdated today
    Backend & APIsAuto-check passed
  • C# and .NET Developer

    Jeffallan/claude-skills

    Guides C# work on .NET 8+: ASP.NET Core APIs, Entity Framework Core data access, Blazor apps and CQRS with MediatR, following a five-step build workflow.

    12k GitHub stars~1.3k tokensUpdated 8 days ago
    Backend & APIsAuto-check passed
  • Django Expert

    Jeffallan/claude-skills

    Builds Django apps and Django REST Framework APIs: models with indexes, ORM query optimization, serializers, viewsets and JWT authentication, with tests.

    12k GitHub stars~1.5k tokensUpdated 8 days ago
    Backend & APIsAuto-check passed
  • FastAPI Expert

    Jeffallan/claude-skills

    Builds async Python APIs with FastAPI and Pydantic V2, covering endpoints, JWT authentication, async SQLAlchemy, WebSockets and pytest checks against the OpenAPI docs.

    12k GitHub stars~1.8k tokensUpdated 8 days ago
    Backend & APIsAuto-check passed

More from hexlet-volunteers/hexlet-sicp

  • Debug Using Debugbar

    hexlet-volunteers/hexlet-sicp

    Inspect what a Laravel request actually did — queries, exceptions, timing, cache, auth, views — by reading the profiling data Laravel Debugbar already captured, via Artisan commands.

    114 GitHub starsUsed in 1 repo~1.5k tokens
    Auto-check passed
  • Socialite Development

    hexlet-volunteers/hexlet-sicp

    Manages OAuth social authentication with Laravel Socialite. An agent skill from hexlet-volunteers/hexlet-sicp.

    114 GitHub starsUsed in 5 repos~1.2k tokens
    Auto-check passed
  • Inertia React Development

    hexlet-volunteers/hexlet-sicp

    Develops Inertia.js v3 React client-side applications. An agent skill from hexlet-volunteers/hexlet-sicp.

    114 GitHub stars~3.4k tokensUpdated 6 days ago
    Auto-check passed

Works with

Categories

Questions about Laravel Query Builder

What does Laravel Query Builder do?

Build filtered, sorted, and included API endpoints using spatie/laravel-query-builder. Laravel Query Builder is an agent skill from hexlet-volunteers/hexlet-sicp. Build filtered, sorted, and included API endpoints using spatie/laravel-query-builder.

When should I use Laravel Query Builder?

Laravel Query Builder fits situations like: mentions query parameters; spatie/laravel-query-builder.

How do I install Laravel Query Builder in Claude Code?

Run `npx skills add hexlet-volunteers/hexlet-sicp --skill laravel-query-builder -a claude-code`. Or copy the skill folder (.agents/skills/laravel-query-builder in hexlet-volunteers/hexlet-sicp) into .claude/skills/laravel-query-builder in your project. Claude Code loads it when a task matches its description.

How do I install Laravel Query Builder in Codex?

Run `npx skills add hexlet-volunteers/hexlet-sicp --skill laravel-query-builder -a codex`. Or copy the skill folder (.agents/skills/laravel-query-builder in hexlet-volunteers/hexlet-sicp) into .agents/skills/laravel-query-builder in your project. Codex loads it when a task matches its description.

Can I use Laravel Query Builder in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add hexlet-volunteers/hexlet-sicp --skill laravel-query-builder -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/laravel-query-builder, .gemini/skills/laravel-query-builder, .github/skills/laravel-query-builder and .opencode/skills/laravel-query-builder in your project.

What does Laravel Query Builder need to run?

SKILL.md names no scripts, command-line tools or credentials: Laravel Query Builder is instructions for the agent only.

Does Laravel Query Builder access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Laravel Query Builder safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Laravel Query Builder use?

Laravel Query Builder is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Laravel Query Builder use?

About 2.4k tokens (SKILL.md is roughly 9.4k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Laravel Query Builder?

Skills that share tags, products or a category with Laravel Query Builder: Laravel Specialist (Jeffallan/claude-skills, 12k stars), Fastcrud (benavlabs/fastcrud, 1.6k stars), Grails Developer Guide (apache/grails-core, 2.9k stars) and C# and .NET Developer (Jeffallan/claude-skills, 12k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Laravel Query Builder?

hexlet-volunteers (a GitHub organization) maintains it in hexlet-volunteers/hexlet-sicp, which has 114 GitHub stars. The repository holds 4 skills in this directory. The repository was last updated on October 5, 2026.

Source: hexlet-volunteers/hexlet-sicp on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.