PHP code example of saasscaleup / laravel-n-plus-one-detector

1. Go to this page and download the library: Download saasscaleup/laravel-n-plus-one-detector library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

saasscaleup / laravel-n-plus-one-detector example snippets




return [
    
    // Whether or not to enable the N+1 Detector
    'enabled' => env('NPLUSONE_ENABLED', true),
    
    // The number of queries below which no alert will be triggered
    'queries_threshold' => env('NPLUSONE_QUERIES_THRESHOLD', 50),
    
    // The number of queries below which no detector will be triggered
    'detector_threshold' => env('NPLUSONE_DETECTOR_THRESHOLD', 10),
    
    // The number in minutes a n+1 query will be stored in memory before being discarded. So it won't repeat itself
    'cache_lifetime' => env('NPLUSONE_CACHE_LIFETIME', 14400), // 10 days
      
    // Slack webhook url for N + 1 Detector
    'slack_webhook_url' => env('NPLUSONE_SLACK_WEBHOOK_URL', ''),

    // Custom webhook url for N + 1 Detector
    'custom_webhook_url' => env('NPLUSONE_CUSTOM_WEBHOOK_URL', ''),

    // notification email address for N + 1 Detector
    'notification_email' => env('NPLUSONE_NOTIFICATION_EMAIL', '[email protected]'), // also possible: '[email protected],[email protected]'

    // notification email subject for N + 1 Detector
    'notification_email_subject' => env('NPLUSONE_NOTIFICATION_EMAIL_SUBJECT', 'N+1 Detector Notification'),

    // Dashboard Middleware for N + 1 Detector
    'dashboard_middleware' => env('NPLUSONE_DASHBOARD_MIDDLEWARE', ['web', 'auth']),

    // Dashboard Pagination for N + 1 Detector
    'dashboard_records_pagination' => env('NPLUSONE_DASHBOARD_RECORDS_PAGINATION', 10),

];

Route::get('/n-plus-one-dashboard', [NPlusOneDashboardController::class, 'index'])->name('n-plus-one.dashboard');

    // Slack webhook url for N + 1 Detector
    'slack_webhook_url' => env('NPLUSONE_SLACK_WEBHOOK_URL', ''),

    // Custom webhook url for N + 1 Detector
    'custom_webhook_url' => env('NPLUSONE_CUSTOM_WEBHOOK_URL', ''),

    // notification email address for N + 1 Detector
    'notification_email' => env('NPLUSONE_NOTIFICATION_EMAIL', '[email protected]'), // also possible: '[email protected],[email protected]'
bash
php artisan vendor:publish --provider="Saasscaleup\NPlusOneDetector\NPlusOneDetectorServiceProvider"
bash
php artisan vendor:publish
bash
php artisan migrate
bash
php artisan route:cache