mcpField
L
laravel-performance-eager-loading

laravel-performance-eager-loading

github.com/noartemDevelopment1378 installsUpdated 2w ago
Repository

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

  1. 01Explicitly load model relations
  2. 02Use load() and loadMissing()
  3. 03Prevent lazy loading in dev and test
  4. 04Verify query counts and relation queries

Use cases

  1. 01Load post authors and comments efficiently
  2. 02Detect accidental lazy loading during development
  3. 03Check relation query volume with a logger
  4. 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-loading

After installing, type/laravel-performance-eager-loadingin Claude Code to confirm it loaded.

Details

From the project README

Eager 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