najibismail/laravel-exception-catcher
Composer 安装命令:
composer require najibismail/laravel-exception-catcher
包简介
A powerful Laravel package that automatically catches exceptions and sends beautifully formatted, responsive email notifications to multiple recipients
README 文档
README
A powerful Laravel package that automatically catches exceptions and sends beautifully formatted, responsive email notifications to multiple recipients.
🚀 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
composer require najibismail/laravel-exception-catcher
The service provider will be automatically registered (Laravel 5.5+).
⚡ Quick Start
-
Publish configuration:
php artisan vendor:publish --provider="NajibIsmail\LaravelExceptionCatcher\ExceptionCatcherServiceProvider" --tag="config"
-
Configure emails in
.env:EXCEPTION_CATCHER_TO_EMAIL="admin@yourapp.com" EXCEPTION_CATCHER_FROM_EMAIL="noreply@yourapp.com"
-
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 }
-
Test it:
php artisan exception:test
⚙️ 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
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' => [ '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
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
Method 1: Using the Trait (Recommended)
The trait automatically handles exception reporting. Simply add it to your Exception Handler:
<?php 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 }
Method 2: Manual Integration
If you prefer manual control, you can manually call the exception emailer:
<?php 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()); } } }
Method 3: Using the Facade
You can also send exception emails manually anywhere in your code:
use NajibIsmail\LaravelExceptionCatcher\Facades\ExceptionCatcher; try { // Your code here } catch (Exception $e) { ExceptionCatcher::handle($e, request()); throw $e; // Re-throw if needed }
🧪 Testing
Command Line Testing
php artisan exception:test [type]
Available Types: runtime, invalid, custom, db, fatal, validation, http
Web Route Testing
GET http://your-app.com/exception-test
GET http://your-app.com/exception-test/runtime
Results: Exception caught → Email sent → Beautiful responsive template
📧 Email Features
- Responsive Design - Adapts to desktop, tablet, and mobile
- Email Client Support - Gmail, Outlook, Apple Mail, Thunderbird
- Enhanced Stack Traces - Color-coded with source indicators (ORIGIN, APP, VENDOR)
- Rich Information - Request data, user details, environment info
- Automatic From Address - Uses configuration or Laravel's default mail settings
- Queue Support - Optional async email sending for better performance
🔍 Troubleshooting
Not Receiving Emails?
- Check your Laravel mail configuration
- Verify recipient email addresses in config
- Check spam/junk folders
- Test Laravel mail with
php artisan tinker:Mail::raw('Test', function($msg) { $msg->to('your-email@example.com')->subject('Test'); });
Command Not Found?
- Run
composer dump-autoload - Verify package installation:
composer show najibismail/laravel-exception-catcher
Web Routes Not Working?
- Clear route cache:
php artisan route:clear - Check if service provider is registered:
php artisan route:list | grep exception-test
Rate Limiting Issues?
- Check cache configuration in
config/cache.php - Clear cache:
php artisan cache:clear - Adjust rate limits in your
.envfile:EXCEPTION_CATCHER_RATE_LIMITING_ENABLED=true EXCEPTION_CATCHER_MAX_EMAILS_PER_HOUR=20 # Increase if needed
- Or disable rate limiting temporarily:
EXCEPTION_CATCHER_RATE_LIMITING_ENABLED=false
🏗️ Package Structure
packages/laravel-exception-catcher/
├── .gitignore # Git ignore rules
├── LICENSE # MIT License
├── README.md # This documentation
├── composer.json # Package configuration
├── config/
│ └── exception-catcher.php # Configuration file
├── resources/
│ └── views/
│ └── exception-email.blade.php # Responsive email template
├── routes/
│ └── web.php # Test routes
└── src/
├── Console/Commands/
│ └── TestExceptionCatcher.php # Test command
├── ExceptionCatcherServiceProvider.php # Service provider
├── ExceptionEmailer.php # Core logic
├── Facades/
│ └── ExceptionCatcher.php # Facade
├── Mail/
│ └── ExceptionNotification.php # Mailable class
└── Traits/
└── SendsExceptionEmails.php # Handler trait
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
� Support
- Issues: GitHub Issues
- Email: najibismail1986@gmail.com
- Discussions: GitHub Discussions
�📄 License
This package is open-sourced software licensed under the MIT license.
🏷️ Version
Current Version: 1.0.8
Laravel Compatibility: 8.x, 9.x, 10.x, 11.x
PHP Compatibility: 8.0+
Made with ❤️ for the Laravel community
najibismail/laravel-exception-catcher 适用场景与选型建议
najibismail/laravel-exception-catcher 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「debug」 「email」 「exception」 「error」 「monitoring」 「notification」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 najibismail/laravel-exception-catcher 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 najibismail/laravel-exception-catcher 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 najibismail/laravel-exception-catcher 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Debug your SimpleBus EventBus and CommandBus
nice output for debug functions for PHP 5.3
Analysis module for finding problematical shop data.
Twig extensions for Tracy Debugger
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-19