@@ -77,11 +77,7 @@ 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\M ail\E xceptionOccurred;
81- use Illuminate\S upport\F acades\L og;
82- use Illuminate\S upport\F acades\M ail;
83- use Symfony\C omponent\E rrorHandler\E rrorRenderer\H tmlErrorRenderer;
84- use Throwable;
80+ use App\T raits\E xceptionNotificationHandlerTrait;
8581` ` `
8682
8783# ### Laravel 8 and Below use:
@@ -97,24 +93,15 @@ Register the package with laravel in `config/app.php` under `providers` with the
97935. Update ` App\E xceptions\H andler.php`
9894
9995# ### Laravel 9 and Above:
100- # #### In `App\Exceptions\Handler.php` replace the `register()` method with:
10196
97+ # #### Add trait to `Handler` class:
10298` ` ` php
103- /**
104- * Register the exception handling callbacks for the application.
105- *
106- * @return void
107- * /
108- public function register()
109- {
110- $this -> reportable(function (Throwable $e ) {
111- $this -> sendEmail($e );
112- });
113- }
99+ use ExceptionNotificationHandlerTrait;
114100` ` `
115101
116102# ### Laravel 8 and Below:
117- # #### In `App\Exceptions\Handler.php` replace the `report()` method with:
103+
104+ # #### Replace the `report()` method with:
118105
119106` ` ` php
120107 /**
@@ -142,37 +129,7 @@ Register the package with laravel in `config/app.php` under `providers` with the
142129 }
143130` ` `
144131
145- 6. In ` App\E xceptions\H andler.php` add the method ` sendEmail()` :
146-
147- # ### Laravel 9 and Above:
148-
149- ` ` ` php
150- /**
151- * Sends an email upon exception.
152- *
153- * @param Throwable $exception
154- *
155- * @return void
156- * /
157- public function sendEmail(Throwable $exception )
158- {
159- try {
160- $content [' message' ] = $exception->getMessage ();
161- $content [' file' ] = $exception->getFile ();
162- $content [' line' ] = $exception->getLine ();
163- $content [' trace' ] = $exception->getTrace ();
164- $content [' url' ] = request()->url ();
165- $content [' body' ] = request()->all ();
166- $content [' ip' ] = request()->ip ();
167- Mail::send(new ExceptionOccurred($content ));
168- } catch (Throwable $exception ) {
169- Log::error($exception );
170- }
171- }
172- ` ` `
173-
174- # ### Laravel 8 and Below:
175-
132+ # #### Add the method `sendEmail()`:
176133` ` ` php
177134 /**
178135 * Sends an email upon exception.
@@ -195,9 +152,9 @@ Register the package with laravel in `config/app.php` under `providers` with the
195152 }
196153` ` `
197154
198- 7 . Configure your email settings in the ` .env` file.
155+ 6 . Configure your email settings in the ` .env` file.
199156
200- 8 . Add the following (optional) settings to your ` .env` file and enter your settings:
157+ 7 . Add the following (optional) settings to your ` .env` file and enter your settings:
201158
202159 * ** Note:** the defaults for these are located in ` config/exception.php`
203160
0 commit comments