@@ -77,7 +77,10 @@ Register the package with laravel in `config/app.php` under `providers` with the
7777# ### Laravel 9 and Above use:
7878
7979` ` ` php
80- use App\T raits\E xceptionNotificationHandlerTrait;
80+ use App\M ail\E xceptionOccurred;
81+ use Illuminate\S upport\F acades\L og;
82+ use Illuminate\S upport\F acades\M ail;
83+ use Throwable;
8184` ` `
8285
8386# ### Laravel 8 and Below use:
@@ -94,9 +97,46 @@ Register the package with laravel in `config/app.php` under `providers` with the
9497
9598# ### Laravel 9 and Above:
9699
97- # #### Add trait to `Handler` class:
100+ # #### Add the `sendEmail()` method:
101+ ` ` ` php
102+ /**
103+ * Sends an email upon exception.
104+ * /
105+ public function sendEmail(Throwable $exception ): void
106+ {
107+ try {
108+ $content = [
109+ ' message' => $exception->getMessage (),
110+ ' file' => $exception->getFile (),
111+ ' line' => $exception->getLine (),
112+ ' trace' => $exception->getTrace (),
113+ ' url' => request()->url (),
114+ ' body' => request()->all (),
115+ ' ip' => request()->ip (),
116+ ];
117+
118+ Mail::send(new ExceptionOccurred($content ));
119+ } catch (Throwable $exception ) {
120+ Log::error($exception );
121+ }
122+ }
123+ ` ` `
124+
125+ # #### Add or update the `register()` method:
98126` ` ` php
99- use ExceptionNotificationHandlerTrait;
127+ /**
128+ * Register the exception handling callbacks for the application.
129+ * /
130+ public function register(): void
131+ {
132+ $this -> reportable(function (Throwable $e ) {
133+ $enableEmailExceptions = config(' exceptions.emailExceptionEnabled' );
134+
135+ if ($enableEmailExceptions && $this -> shouldReport($e )) {
136+ $this -> sendEmail($e );
137+ }
138+ });
139+ }
100140` ` `
101141
102142# ### Laravel 8 and Below:
0 commit comments