L
laravel:performance-eager-loading
About laravel:performance-eager-loading
A Laravel skill for preventing N+1 queries and reducing relation-loading overhead. It covers eager loading, lazy-loading safeguards, and query verification for developers optimizing database access.
Key features
- 01Explicit eager loading
- 02Post-fetch relation loading
- 03Development lazy-loading safeguards
- 04Query-count verification
Use cases
- 01Reduce relation queries in paginated results
- 02Detect accidental lazy loading in development
- 03Check query counts with tests or debugging tools
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ jpcaparas/ superpowers-laravel --skill laravel:performance-eager-loadingAfter installing, type/laravel:performance-eager-loadingin Claude Code to confirm it loaded.
Details
From the project READMEEager Loading and N+1 Prevention
Load Relations Explicitly
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):
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
Comments
Markdown supported