laravel-query-builders

Encapsulate Laravel query logic in type-safe custom builders.

1|Updated Oct 10, 2025
One-click install
npx skills add https://github.com/nextplus896/durra-alaseel --skill laravel-query-builders
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-query-builders
Source: https://github.com/nextplus896/durra-alaseel/tree/main/.github/skills/claude-laravel/laravel-query-builders
Command: npx skills add https://github.com/nextplus896/durra-alaseel --skill laravel-query-builders

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Custom query builders for type-safe, composable database queries in Laravel, helping you centralize complex query logic and improve IDE support.

Core Features & Use Cases

  • Type-safe custom builders for common queries, improving autocomplete and reducing errors.
  • Nested and fluent query composition with methods like wherePending, whereCustomer, withRelated.
  • Automatic model integration via Laravel 11+ attributes or static properties, and easy reuse across controllers and services.
  • Example: encapsulate customer-scoped queries in a single builder to avoid duplicating code.

Quick Start

  • Create a builder class extending Illuminate\Database\Eloquent\Builder (e.g., OrderBuilder).
  • Register the builder with a model using #[UseEloquentBuilder(OrderBuilder::class)] or protected static string $eloquentBuilder = OrderBuilder::class;
  • Use it in code: Order::query()->wherePending()->get();

Frequently Asked Questions about laravel-query-builders

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

FAQPage Schema
How do I create type-safe custom query builders in Laravel?

Type-safe custom query builders in Laravel are created by extending Illuminate\Database\Eloquent\Builder with a dedicated class, encapsulating complex query logic to improve IDE autocomplete and reduce errors. You then register this builder with your Eloquent model.

How do I register a custom Eloquent builder with a Laravel model?

Register a custom Eloquent builder with a Laravel model using the #[UseEloquentBuilder(OrderBuilder::class)] attribute in Laravel 11+, or by setting the protected static string $eloquentBuilder property. This automatically routes model queries to your custom class.

What is the best way to organize reusable Eloquent queries in Laravel?

The best way to organize reusable Eloquent queries is encapsulating them in composable builder classes. This approach centralizes query logic within dedicated builders, preventing code duplication across controllers and services while maintaining type safety.

Can I use nested and fluent query composition with Laravel Eloquent builders?

Yes, you can use nested and fluent query composition by chaining custom methods like wherePending, whereCustomer, and withRelated on your builder classes. This allows you to build complex database queries seamlessly across models, controllers, and services.

Does this Laravel query builder approach work with older PHP versions?

This approach requires Laravel 11+ if you use attributes like #[UseEloquentBuilder] for model integration. However, you can achieve similar type-safe builder integration on older versions by using protected static string properties instead of PHP attributes.