PHP code example of msemeen / laravel-error-reporter

1. Go to this page and download the library: Download msemeen/laravel-error-reporter 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/ */

    

msemeen / laravel-error-reporter example snippets


// Never miss an error again!
try {
    // Your risky code here
} catch (\Exception $e) {
    ErrorReporter::report($e); // That's it!
}

// In your exception handler add below function
use Msemeen\ErrorReporter\Facades\ErrorReporter;

public function register()
{
    $this->reportable(function (Throwable $e) {
        ErrorReporter::report($e);
    });
}

// Manually send important notifications
ErrorReporter::send(
    'Payment service is down!', 
    'Critical Service Alert'
);

ErrorReporter::report($exception, function($message) {
    return $message->setTitle('Custom Title')
                  ->addContext('user_id', auth()->id())
                  ->addContext('request_data', request()->all());
});

// config/error-reporter.php

return [
    'enabled' => env('ERROR_REPORTER_ENABLED', true),
    
    'grouping' => [
        'enabled' => true,
        'threshold' => 5, // Group similar errors if they occur within 5 minutes
    ],
    
    'channels' => [
        'discord' => [
            'enabled' => env('ERROR_REPORTER_DISCORD_ENABLED', false),
            'webhook' => env('ERROR_REPORTER_DISCORD_WEBHOOK'),
            'username' => env('ERROR_REPORTER_DISCORD_USERNAME', 'Error Reporter'),
        ],
        
        'email' => [
            'enabled' => env('ERROR_REPORTER_EMAIL_ENABLED', false),
            'to' => env('ERROR_REPORTER_EMAIL_TO'),
            'from' => env('ERROR_REPORTER_EMAIL_FROM'),
            'subject' => env('ERROR_REPORTER_EMAIL_SUBJECT', 'Application Error Alert'),
        ],
        
        'slack' => [
            'enabled' => env('ERROR_REPORTER_SLACK_ENABLED', false),
            'webhook' => env('ERROR_REPORTER_SLACK_WEBHOOK'),
            'username' => env('ERROR_REPORTER_SLACK_USERNAME', 'Error Reporter'),
            'icon' => env('ERROR_REPORTER_SLACK_ICON', ':warning:'),
            'channel' => env('ERROR_REPORTER_SLACK_CHANNEL'),
        ],
    ],
    
    'ignore_exceptions' => [
        // List exception classes to ignore
        \Illuminate\Auth\AuthenticationException::class,
        \Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class,
    ],
];

// In your ServiceProvider or exception handler
ErrorReporter::ignoreExceptions([
    \Illuminate\Validation\ValidationException::class,
    \Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class,
]);
bash
php artisan vendor:publish --tag=error-reporter-config
bash
php artisan vendor:publish --tag=error-reporter-views