Write performant Eloquent queries with eager loading, reusable scopes, and strict lazy-loading prevention in Laravel. Use when defining model relationships, creating query scopes, or processing large datasets with chunk/cursor. (triggers: app/Models/**/*.php, scope, with, eager, chunk, model)
$fillable, $casts, and relationships.preventLazyLoading(!app()->isProduction()) in AppServiceProvider.scopeActive(), scopeVerified() for reusable filters.with() for all relationship access.chunk() or cursor() instead of get().See implementation examples for model scopes, eager loading, and directory structure.
with() or $with for relationships. Never access relationship properties in a loop without eager loading (N+1 Prevention).Eloquent::preventLazyLoading(!app()->isProduction()) in AppServiceProvider::boot() to throw LazyLoadingViolationException in local/dev.chunk(), lazy(), or cursor() for processing many records without memory issues (Memory Efficiency).scopeName(Builder $query): Builder methods in models for reusable query filters.User::active()->verified()->get()) to keep controllers from duplicating query logic.protected $fillable array; use $request->validated() for Model::create().protected $casts for dates, JSON, and custom types to ensure data consistency.with() or $with; never in loops.select *: Specify required columns to limit data transfer.