PHP code example of najibismail / laravel-exception-catcher

1. Go to this page and download the library: Download najibismail/laravel-exception-catcher 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/ */

    

najibismail / laravel-exception-catcher example snippets


   use NajibIsmail\LaravelExceptionCatcher\Traits\SendsExceptionEmails;
   
   class Handler extends ExceptionHandler
   {
       use SendsExceptionEmails;
       
       // The trait automatically handles exception reporting
       // No need to override the report() method
   }
   

return [
    'enabled' => env('EXCEPTION_CATCHER_ENABLED', true),
    
    'emails' => [
        'to' => explode(',', env('EXCEPTION_CATCHER_TO_EMAIL', '[email protected]')),
        'from' => env('EXCEPTION_CATCHER_FROM_EMAIL', '[email protected]'),
        'from_name' => env('EXCEPTION_CATCHER_FROM_NAME', 'Exception Catcher'),
    ],
    
    'queue_enabled' => env('EXCEPTION_CATCHER_QUEUE_ENABLED', false),
    'uminate\Validation\ValidationException',
        'Symfony\Component\HttpKernel\Exception\HttpException',
    ],
    
    'reportable_exceptions' => [
        // Example: 'App\Exceptions\CustomException',
        // Leave empty to report all exceptions (except skipped ones)
    ],
    
    '

'skip_exceptions' => [
    Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class,
    'Illuminate\Auth\AuthenticationException',
    'Illuminate\Validation\ValidationException',
],

'reportable_exceptions' => [
    'App\Exceptions\CustomException',
    'Symfony\Component\Debug\Exception\FatalErrorException',
],

'rate_limiting' => [
    'enabled' => true,              // Enable/disable rate limiting
    'max_emails_per_hour' => 10,    // Maximum emails per hour
    'cache_key_prefix' => 'exception_catcher_',  // Cache key prefix
],



namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use NajibIsmail\LaravelExceptionCatcher\Traits\SendsExceptionEmails;
use Throwable;

class Handler extends ExceptionHandler
{
    use SendsExceptionEmails;
    
    // The trait automatically overrides the report() method
    // No additional code needed
}



namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
    public function report(Throwable $exception)
    {
        parent::report($exception);

        // Send exception email
        if (app()->bound('exception.emailer')) {
            app('exception.emailer')->handle($exception, request());
        }
    }
}

use NajibIsmail\LaravelExceptionCatcher\Facades\ExceptionCatcher;

try {
    // Your code here
} catch (Exception $e) {
    ExceptionCatcher::handle($e, request());
    throw $e; // Re-throw if needed
}

   Mail::raw('Test', function($msg) {
       $msg->to('[email protected]')->subject('Test');
   });
   
bash
   php artisan vendor:publish --provider="NajibIsmail\LaravelExceptionCatcher\ExceptionCatcherServiceProvider" --tag="config"
   
bash
   php artisan exception:test
   
bash
php artisan exception:test [type]