PHPackages                             najibismail/laravel-exception-catcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. najibismail/laravel-exception-catcher

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

najibismail/laravel-exception-catcher
=====================================

A powerful Laravel package that automatically catches exceptions and sends beautifully formatted, responsive email notifications to multiple recipients

v1.0.8(8mo ago)03MITBladePHP ^8.0|^8.1|^8.2|^8.3

Since Aug 19Pushed 8mo agoCompare

[ Source](https://github.com/najibismail/laravel-exception-catcher)[ Packagist](https://packagist.org/packages/najibismail/laravel-exception-catcher)[ Docs](https://github.com/najibismail/laravel-exception-catcher)[ RSS](/packages/najibismail-laravel-exception-catcher/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (10)Used By (0)

Laravel Exception Catcher
=========================

[](#laravel-exception-catcher)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4ffd79b89c4a2a8986412f9d4e349bee00825a62456d0aea081c2d13071290f7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e616a696269736d61696c2f6c61726176656c2d657863657074696f6e2d636174636865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/najibismail/laravel-exception-catcher)[![Total Downloads](https://camo.githubusercontent.com/d3d4ade20fe7f28a112a0040a49a6961b68eca9d2c1aac9bb1d608fe5e0f54d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e616a696269736d61696c2f6c61726176656c2d657863657074696f6e2d636174636865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/najibismail/laravel-exception-catcher)[![License](https://camo.githubusercontent.com/000bea8153d0180da33eb994509ee8df46f1dd215aa5002ca7bd212531d54727/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e616a696269736d61696c2f6c61726176656c2d657863657074696f6e2d636174636865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/najibismail/laravel-exception-catcher)[![PHP Version](https://camo.githubusercontent.com/a7973c706a0d1b451489c977409f29aabb9ca061553bd03cd0035fc0c81184ae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e616a696269736d61696c2f6c61726176656c2d657863657074696f6e2d636174636865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/najibismail/laravel-exception-catcher)

A powerful Laravel package that automatically catches exceptions and sends beautifully formatted, responsive email notifications to multiple recipients.

🚀 Features
----------

[](#-features)

- 🚨 **Automatic Exception Catching** - Seamlessly integrates with Laravel's exception handler
- 📧 **Multiple Recipients** - Send alerts to multiple email addresses
- 📱 **Responsive Email Design** - Beautiful emails that work on all devices and email clients
- ⚡ **Rate Limiting** - Prevents email spam with intelligent throttling (enabled by default)
- 🔧 **Configurable Filtering** - Choose which exception types to report/skip with blacklist and whitelist support
- 📊 **Rich Information** - Includes request data, stack trace, user info, and environment details
- ⚙️ **Queue Support** - Async email sending for better performance
- 🧪 **Built-in Testing** - Command line and web testing tools included
- 🎨 **Stack Trace Enhancement** - Color-coded, row-by-row stack traces with source type indicators
- ✅ **Enable/Disable Control** - Easy toggle for exception catching functionality

📦 Installation
--------------

[](#-installation)

```
composer require najibismail/laravel-exception-catcher
```

The service provider will be automatically registered (Laravel 5.5+).

⚡ Quick Start
-------------

[](#-quick-start)

1. **Publish configuration**:

    ```
    php artisan vendor:publish --provider="NajibIsmail\LaravelExceptionCatcher\ExceptionCatcherServiceProvider" --tag="config"
    ```
2. **Configure emails in `.env`**:

    ```
    EXCEPTION_CATCHER_TO_EMAIL="admin@yourapp.com"
    EXCEPTION_CATCHER_FROM_EMAIL="noreply@yourapp.com"
    ```
3. **Add to your Exception Handler** (`app/Exceptions/Handler.php`):

    ```
    use NajibIsmail\LaravelExceptionCatcher\Traits\SendsExceptionEmails;

    class Handler extends ExceptionHandler
    {
        use SendsExceptionEmails;

        // The trait automatically handles exception reporting
        // No need to override the report() method
    }
    ```
4. **Test it**:

    ```
    php artisan exception:test
    ```

⚙️ Configuration
----------------

[](#️-configuration)

Edit `config/exception-catcher.php` to customize behavior:

```
return [
    'enabled' => env('EXCEPTION_CATCHER_ENABLED', true),

    'emails' => [
        'to' => explode(',', env('EXCEPTION_CATCHER_TO_EMAIL', 'admin@example.com')),
        'from' => env('EXCEPTION_CATCHER_FROM_EMAIL', 'noreply@example.com'),
        'from_name' => env('EXCEPTION_CATCHER_FROM_NAME', 'Exception Catcher'),
    ],

    'queue_enabled' => env('EXCEPTION_CATCHER_QUEUE_ENABLED', false),
    'include_stack_trace' => env('EXCEPTION_CATCHER_INCLUDE_STACK_TRACE', true),

    'rate_limiting' => [
        'enabled' => env('EXCEPTION_CATCHER_RATE_LIMITING_ENABLED', true),
        'max_emails_per_hour' => env('EXCEPTION_CATCHER_MAX_EMAILS_PER_HOUR', 10),
        'cache_key_prefix' => 'exception_catcher_',
    ],

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

    'reportable_exceptions' => [
        // Example: 'App\Exceptions\CustomException',
        // Leave empty to report all exceptions (except skipped ones)
    ],

    'include_request_data' => env('EXCEPTION_CATCHER_INCLUDE_REQUEST', true),
];
```

### Configuration Options Explained

[](#configuration-options-explained)

#### Exception Filtering

[](#exception-filtering)

**Skip Exceptions (Blacklist)**

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

These exception types will **NOT** be reported via email.

**Reportable Exceptions (Whitelist)**

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

If this array is **not empty**, only these exception types will be reported. If **empty**, all exceptions (except skipped ones) will be reported.

#### Rate Limiting

[](#rate-limiting)

```
'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
],
```

### Environment Variables

[](#environment-variables)

Add these to your `.env` file:

```
# Exception Catcher Configuration
EXCEPTION_CATCHER_ENABLED=true
EXCEPTION_CATCHER_TO_EMAIL="admin@yourapp.com,dev@yourapp.com"
EXCEPTION_CATCHER_FROM_EMAIL="noreply@yourapp.com"
EXCEPTION_CATCHER_FROM_NAME="Your App Name"
EXCEPTION_CATCHER_QUEUE_ENABLED=false
EXCEPTION_CATCHER_INCLUDE_STACK_TRACE=true
EXCEPTION_CATCHER_INCLUDE_REQUEST=true

# Rate Limiting Configuration
EXCEPTION_CATCHER_RATE_LIMITING_ENABLED=true
EXCEPTION_CATCHER_MAX_EMAILS_PER_HOUR=10

# Laravel Mail Configuration
MAIL_MAILER=smtp
MAIL_HOST=your-smtp-host
MAIL_PORT=587
MAIL_USERNAME=your-email
MAIL_PASSWORD=your-password
MAIL_ENCRYPTION=tls
```

🔧 Integration Methods
---------------------

[](#-integration-methods)

### Method 1: Using the Trait (Recommended)

[](#method-1-using-the-trait-recommended)

The trait automatically handles exception reporting. Simply add it to your Exception Handler:

```
