Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Query Detector Laravel Package

beyondcode/laravel-query-detector

Detect N+1 database queries in Laravel during development. Monitors queries in real time and alerts you when repeated queries indicate missing eager loading, helping you optimize performance and reduce unnecessary database calls.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Performance Optimization for High-Impact Features:

    • Critical for scalable features (e.g., real-time analytics dashboards, user-generated content platforms) where N+1 queries degrade performance under load. Directly impacts latency SLAs (e.g., "<200ms for 99% of requests").
    • API-heavy products: Reduces redundant queries in GraphQL/REST endpoints, improving payload efficiency and client-side rendering speed (e.g., React/Vue apps).
    • Data-intensive applications: Ideal for SaaS platforms with complex relationships (e.g., Post::morphTo(), Order::hasManyThrough()) where eager loading is frequently overlooked.
  • Developer Productivity Initiatives:

    • Shift-left performance: Embeds query optimization into daily development (e.g., alerts in Debugbar, console logs, or JSON responses), reducing "it works but is slow" surprises.
    • Onboarding acceleration: New engineers immediately identify query bottlenecks (e.g., "Why is User::with('posts')->get() slow?") via real-time feedback, cutting ramp-up time by ~30%.
    • Code review efficiency: Provides actionable insights for PRs (e.g., "This endpoint has 5 N+1 queries—consider eager loading"), reducing back-and-forth by ~40%.
  • Cost and Scalability Roadmap:

    • Database cost reduction: Targets RDS/Aurora query costs (e.g., $1,200/month saved by eliminating redundant queries in production).
    • Scalability headroom: Prevents database bottlenecks during traffic spikes (e.g., Black Friday sales, viral growth), ensuring linear scaling with user growth.
    • Serverless optimization: Reduces Lambda cold starts and dyno costs in Laravel Vapor by minimizing query chattiness (e.g., 20% cheaper for high-traffic APIs).
  • Technical Debt Mitigation:

    • Proactive performance culture: Enforces eager loading discipline across teams via configurable thresholds (e.g., "Alert on >2 N+1 queries/endpoint").
    • CI/CD integration: Can fail builds if N+1 queries exceed thresholds (e.g., >3 queries/endpoint), enforced via GitHub Actions or GitLab CI templates.
    • Legacy code modernization: Identifies hidden N+1 patterns in older codebases (e.g., pre-Laravel 5.5), enabling incremental optimizations.
  • Cross-Team Collaboration:

    • Backend-Frontend alignment: Exposes query inefficiencies in API responses (JSON output) for React/Vue teams to optimize data fetching (e.g., "This endpoint returns 100 queries—consider GraphQL batching").
    • Product-manager metrics: Provides quantifiable wins (e.g., "Reduced checkout flow queries by 60%, improving conversion by 5%") for stakeholder reports.
    • Security compliance: Helps meet performance SLAs for PCI/DSS compliance (e.g., "No endpoint exceeds 100ms response time").

When to Consider This Package

  • Adopt if:

    • Your Laravel app exceeds 50+ queries/endpoint in staging/production (indicates N+1 risk).
    • Developer onboarding is a bottleneck due to performance surprises in PRs.
    • You’re building a scalable SaaS product with polymorphic relationships or deeply nested Eloquent models.
    • Database costs are a line-item in your budget (e.g., RDS/Aurora pricing).
    • Your team lacks automated performance guardrails (e.g., no CI checks for query counts).
    • You use Laravel Debugbar or Clockwork and want to surface N+1 issues proactively.
  • Look elsewhere if:

    • Your app is read-heavy but low-traffic (e.g., internal tools with <100 users).
    • You’re using raw SQL queries exclusively (no Eloquent relationships).
    • Your team already has strict eager-loading discipline (e.g., enforced via code reviews).
    • You’re on Laravel Octane or Swoole, where query optimization is handled at the server level.
    • Your primary bottleneck is CPU/memory, not database queries (profile with Blackfire first).
    • You need production monitoring (this is dev-only; use Laravel Telescope or Sentry for runtime tracking).

How to Pitch It (Stakeholders)

For Executives (CTO, VP Engineering):

*"This is a no-code, high-impact way to cut database costs and improve scalability without hiring more engineers. By automatically detecting N+1 query patterns during development, we’ll:

  • Reduce RDS/Aurora costs by ~20% (savings: $X/month).
  • Eliminate ‘slow endpoints’ surprises in production, saving ~10 hours/week in debugging.
  • Accelerate feature delivery by catching performance issues before code reviews.
  • Future-proof our stack for traffic spikes (e.g., Black Friday, viral growth).

It’s a 5-minute install, zero runtime overhead, and pay-as-you-go—only active in development. Let’s pilot it on our [highest-traffic feature] and measure the impact."*

For Engineering Leaders (Tech Leads, Dev Managers):

*"This solves two critical problems:

  1. N+1 queries are the #1 cause of slow endpoints—this package catches them in real-time (alerts, Debugbar, or console logs).
  2. Onboarding is painful because new engineers keep writing inefficient queries—this teaches best practices automatically.

Key benefits:

  • Reduces query counts by 30–50% in new features (measured in [Project X]).
  • Cuts PR review time by surfacing issues upfront (e.g., ‘This endpoint has 5 N+1 queries’).
  • Works with our stack: Debugbar, Clockwork, or JSON output for APIs.
  • Zero maintenance: Just install and go—no false positives if configured right.

Proposal: Let’s enable this for all new features and legacy codebases where we’ve seen query spikes. I’ll show you a before/after on [Endpoint Y] next sprint."*

For Developers (Backend Team):

*"Tired of ‘why is this endpoint slow?’ mysteries? This package automatically detects N+1 queries and tells you exactly what to fix:

  • Alerts in your browser (like a red flag).
  • Debugbar integration (see queries while debugging).
  • Console logs (for IDE users).
  • JSON output (for API devs).

How it works:

  1. Install (composer require beyondcode/laravel-query-detector --dev).
  2. Write your code as usual.
  3. Boom—it catches lazy-loaded relationships (e.g., foreach ($users as $user) { $user->posts }).

Example fix:

// Before (N+1):
$users = User::all();
foreach ($users as $user) {
    echo $user->posts->count(); // 🚨 N+1 query!
}

// After (fixed):
$users = User::with('posts')->get(); // ✅ 1 query

Let’s enable this for [Project Z]—it’ll save us hours of debugging."*

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport