laravel-exception-notifier icon indicating copy to clipboard operation
laravel-exception-notifier copied to clipboard

Laravel 11 Support

Open pms07 opened this issue 10 months ago • 1 comments

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.!

pms07 avatar Jan 13 '25 17:01 pms07

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();

Peeet93 avatar Jun 13 '25 13:06 Peeet93