laraveldaily-eloquent-audit

Analyze Laravel Eloquent usage for N+1 queries and correctness issues.

132|33|Updated Mar 10, 2026
One-click install
npx skills add https://github.com/LaravelDaily/AI-Workflows-For-Laravel --skill laraveldaily-eloquent-audit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laraveldaily-eloquent-audit
Source: https://github.com/LaravelDaily/AI-Workflows-For-Laravel/tree/main/skills/laraveldaily-eloquent-audit
Command: npx skills add https://github.com/LaravelDaily/AI-Workflows-For-Laravel --skill laraveldaily-eloquent-audit

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Identifies performance, correctness, and maintainability issues in Laravel Eloquent usage so teams can reduce query bloat, fix hidden N+1s, avoid large memory usage, and make model code safer and more predictable.

Core Features & Use Cases

  • N+1 Detection: Locate relationship access patterns in controllers, Blade templates, components, and accessors that cause N+1 queries and recommend eager loading or withCount/withSum alternatives.
  • Query Efficiency: Flag filtering done in PHP after get/all, missing select column constraints in API responses, and large resultset hydration in jobs/commands that should use chunk, cursor, or lazy.
  • Model Correctness: Highlight missing or incorrect casts, mass-assignment risks, absent uniqueness constraints for upserts, transaction gaps for multi-step writes, unsafe convenience helper usage, and $with over-fetching.
  • Operational Guidance: Tie findings to migrations where possible, classify severity, and provide actionable suggestions such as using with(), withCount(), select(), DB::transaction(), Model::shouldBeStrict(), and Prunable traits.
  • Use Case: Run a repository scan to produce a findings-by-category report showing file locations, severity, and concrete code-level remediation advice for each issue.

Quick Start

Audit the Laravel repository for Eloquent issues and return a structured report with file-level evidence, severities, and suggested fixes for N+1s, casts, mass-assignment, large-memory loads, and relationship anti-patterns.

Frequently Asked Questions about laraveldaily-eloquent-audit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find N+1 query problems in my Laravel Eloquent codebase?

To detect N+1 query problems in Laravel Eloquent, scan controllers, Blade templates, and Livewire components for relationship access patterns. The audit flags query bloat with file-and-line evidence and recommends eager loading using with(), or withCount/withSum alternatives to resolve the issue.

How can I check Laravel models for mass assignment risks and missing casts?

Check Laravel models for mass assignment risks and missing casts by auditing model definitions against migrations. The audit highlights incorrect casts, unsafe mass assignment vulnerabilities, and absent uniqueness constraints for upserts, providing actionable code-level remediation advice.

What is the best way to prevent large memory usage when processing Eloquent collections in jobs?

Prevent large memory usage in Eloquent collections by flagging large resultset hydration in jobs and commands during an audit. The analysis recommends replacing get() or all() with chunk, cursor, or lazy collection methods to optimize query efficiency and reduce memory consumption.

Does the Eloquent audit scan Blade templates and Livewire components for query issues?

Yes, the Eloquent audit scans Blade templates and Livewire components for query issues. It analyzes these views alongside controllers, models, migrations, jobs, commands, and tests to detect N+1 queries, inefficient collection filtering, and relationship anti-patterns across the entire codebase.

How do I identify missing database transactions in Laravel multi-step writes?

Identify missing database transactions in Laravel multi-step writes by auditing Eloquent usage for transaction omissions. The audit classifies severity and suggests wrapping operations in DB::transaction() to ensure data integrity and make model code safer and more predictable.

When should I not use global $with for Eloquent eager loading?

You should avoid global $with for Eloquent eager loading when it causes over-fetching data unnecessary for specific responses. The audit flags $with over-fetching and suggests applying shouldBeStrict() and targeted select() column constraints to optimize API response efficiency.