laravel-exception-notifier
laravel-exception-notifier copied to clipboard
Laravel 11 Support
Hi, I am using this package from laravel 5.7.
In Laravel 11, the Exception handler flow is changed with protected Exception classes, I am trying to work around with this package to send an email while any exception occurs. Can anyone suggest how do we migrate to laravel 11 from laravel 10
This is one reference on for getting HTML of error page but not sure how we can implement it 😅 https://stackoverflow.com/questions/79086239/custom-exceptionhandler-in-laravel-11-how-to-get-html-of-error
Thanks in advance.!
If you publish all files via php artisan vendor:publish you can the change your basic bootstrap/app.php to this
use App\Mail\ExceptionOccurred;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(web: __DIR__ . '/../routes/web.php', commands: __DIR__ . '/../routes/console.php', health: '/up')
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
$exceptions->report(function (Throwable $e) {
// Only notify if enabled in config
if(config('exceptions.emailExceptionEnabled')) {
try {
// Prepare exception details
$content = [
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTrace(),
'url' => request()?->url(),
'body' => request()?->all(),
'ip' => request()?->ip(),
];
// Send the exception notification email
Mail::send(new ExceptionOccurred($content));
} catch(Throwable $ex) {
Log::error($ex);
}
}
});
})
->create();