Skip to content
Back to skills

Performance Eager Loading

ASecurity

Prevent N+1 queries by eager loading; enable lazy-loading protection in non-production; choose selective fields

  • 147 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added June 6, 2026
testingphpperformance

Security analysis

A100/100

Scanned June 6, 2026

npx -y skills add jpcaparas/superpowers-laravel --skill performance-eager-loading --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Performance Eager Loading?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Performance Eager Loading
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/jpcaparas-performance-eager-loading/badge)](https://www.skillsdirectory.com/skills/jpcaparas-performance-eager-loading)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: laravel:performance-eager-loading
description: Prevent N+1 queries by eager loading; enable lazy-loading protection in non-production; choose selective fields
---

# Eager Loading and N+1 Prevention

## Load Relations Explicitly

```php
Post::with(['author', 'comments'])->paginate();
```

- Use `load()`/`loadMissing()` after fetching models when needed
- Select only required columns for both base query and relations

## Guard Against Lazy Loading in Dev/Test

Add to a service provider (non-production):

```php
Model::preventLazyLoading(! app()->isProduction());
```

## Verify

- Use a query logger or debugbar to confirm relation queries are minimized
- Add tests that assert counts or avoid unexpected query spikes

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.