DEV Community

Cover image for 🚀 Boost Your Laravel Performance with Real-Time Laravel N+1 Query Detection! 🛠️
ScaleUp SaaS
ScaleUp SaaS

Posted on

🚀 Boost Your Laravel Performance with Real-Time Laravel N+1 Query Detection! 🛠️

Sure! Here's a revised version tailored specifically for dev.to:


🚀 Boost Your Laravel Performance with Real-Time N+1 Query Detection! 🛠️

As Laravel developers, we've all faced the dreaded N+1 query problem at some point. It's a silent performance killer that can turn a blazing-fast application into a sluggish one. But fear not! Introducing Laravel N+1 Query Detector, a powerful tool to help you identify and resolve N+1 query issues in real-time.

🔗 Check it out on GitHub

Why You Need This

N+1 queries occur when your application executes additional queries inside a loop, leading to a significant performance hit. Identifying these queries manually can be a daunting task, especially in large applications. Our package simplifies this by detecting N+1 queries as they happen, providing detailed insights and advanced notifications to keep your application running smoothly.

Key Features

  • Real-time Detection: Catch N+1 queries as they happen, ensuring your application's performance remains top-notch.
  • Detailed Insights: Get comprehensive details about each detected N+1 query, including the class and methods involved.
  • Advanced Notifications: Stay informed with alerts via Slack, webhooks, or email.
  • Rich Admin Dashboard: View all N+1 warnings in a user-friendly dashboard.
  • Team-Friendly: Perfect for solo developers and teams working collaboratively.
  • Compatibility: Supports Laravel 5.5+ and PHP 7+.

Installation

Getting started is easy. Install the package via composer:

composer require --dev saasscaleup/laravel-n-plus-one-detector
Enter fullscreen mode Exit fullscreen mode

Publish the package's configuration and migration files:

php artisan vendor:publish --provider="SaasScaleUp\NPlusOneDetector\NPlusOneDetectorServiceProvider"
Enter fullscreen mode Exit fullscreen mode

Run the migrations to create the necessary database table:

php artisan migrate
Enter fullscreen mode Exit fullscreen mode

Configuration

Edit the config/n-plus-one.php file to set thresholds, notification preferences, and more.

Usage

The package automatically listens to your database queries and detects N+1 issues in real-time. Access the admin dashboard to view all warnings:

Route::get('/nplusone/dashboard', [NPlusOneDashboardController::class, 'index'])->name('nplusone.dashboard');
Enter fullscreen mode Exit fullscreen mode

Dashboard

Notifications

Configure notifications to be sent via Slack, webhook, or email. Set your notification preferences in the config/n-plus-one.php file to stay informed about N+1 issues in your application.

Slack notification

Slack

Webhook notification

webhook

Email notification

Image description

By leveraging Laravel N+1 Query Detector, you can ensure your application runs smoothly and efficiently, providing the best experience for your users. Start detecting and fixing N+1 queries today!

🔗 Check it out on GitHub


This should help you effectively share your Laravel N+1 Query Detector package with the dev.to community.

Top comments (0)