L
laravel-performance-eager-loading
About laravel-performance-eager-loading
laravel-performance-eager-loading is a Laravel skill focused on loading model relations efficiently and preventing N+1 queries. It covers explicit relation loading, development and test safeguards, and query verification.
Key features
- 01Explicitly load model relations
- 02Use load() and loadMissing()
- 03Prevent lazy loading in dev and test
- 04Verify query counts and relation queries
Use cases
- 01Load post authors and comments efficiently
- 02Detect accidental lazy loading during development
- 03Check relation query volume with a logger
- 04Test for unexpected query increases
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ noartem/ skills --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