eloquent-patterns

Implement Eloquent query patterns to reduce database round-trips in Laravel.

9|1|Updated Jun 16, 2026
One-click install
npx skills add https://github.com/AratKruglik/antigravity-sdlc --skill eloquent-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: eloquent-patterns
Source: https://github.com/AratKruglik/antigravity-sdlc/tree/main/plugins/laravel-plugin/skills/eloquent-patterns
Command: npx skills add https://github.com/AratKruglik/antigravity-sdlc --skill eloquent-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides best practices and patterns for working with Eloquent to avoid common performance pitfalls (like N+1 queries), ensure safe and maintainable queries, and promote reusable query logic and proper relationships.

Core Features & Use Cases

  • Eager loading strategies to prevent N+1.
  • Use of model scopes for reusable query fragments.
  • Safe mass assignment and proper relationship declarations.
  • Guidance on counts, aggregates, batch operations, soft deletes, and advanced queries.

Quick Start

Refactor a typical N+1 query in Laravel using eager loading and show the before/after results.

Frequently Asked Questions about eloquent-patterns

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

FAQPage Schema
How do I fix N+1 query problems in Laravel Eloquent?

Fix N+1 query problems in Laravel Eloquent by implementing eager loading strategies using the `with()` method. This approach reduces database round-trips by fetching related models in a single query, significantly improving application responsiveness for complex relationships.

What are model scopes used for in Laravel query optimization?

Model scopes in Laravel query optimization extract reusable query fragments. By defining explicit scopes, developers promote maintainable and reusable query logic, ensuring consistent constraints across the application without code duplication.

How do I ensure safe mass assignment with Eloquent models?

Ensure safe mass assignment with Eloquent models by properly configuring fillable properties and making explicit relationship declarations. This practice prevents unauthorized attribute updates during batch operations, maintaining data security.

Can I use Eloquent batch operations for performance-sensitive data access?

Yes, you can use Eloquent batch operations for performance-sensitive data access. They process large datasets efficiently by reducing individual query overhead, complementing eager loading and aggregates to maintain high responsiveness in Laravel projects.

What is the best way to handle counts and aggregates in Eloquent?

The best way to handle counts and aggregates in Eloquent is using dedicated aggregate methods rather than manually counting collections. This minimizes database round-trips and memory usage, keeping performance-sensitive data access highly responsive.