1- # Laravel Exception Notifier | A Laravel 5, 6, 7, and 8 Exceptions Email Notification [ Package] ( https://packagist.org/packages/jeremykenedy/laravel-exception-notifier )
1+ # Laravel Exception Notifier | A Laravel 5, 6, 7, 8, and 9 Exceptions Email Notification [ Package] ( https://packagist.org/packages/jeremykenedy/laravel-exception-notifier )
22
33[ ![ Total Downloads] ( https://poser.pugx.org/jeremykenedy/laravel-exception-notifier/d/total.svg )] ( https://packagist.org/packages/jeremykenedy/laravel-exception-notifier )
44[ ![ Latest Stable Version] ( https://poser.pugx.org/jeremykenedy/laravel-exception-notifier/v/stable.svg )] ( https://packagist.org/packages/jeremykenedy/laravel-exception-notifier )
@@ -28,12 +28,18 @@ Get the errors and fix them before the client even reports them, that's why this
2828## Installation Instructions
29291 . From your projects root folder in terminal run:
3030
31- Laravel 7 + use:
31+ Laravel 9 + use:
3232
3333 ``` bash
3434 composer require jeremykenedy/laravel-exception-notifier
3535 ```
3636
37+ Laravel 7-8 use:
38+
39+ ` ` ` bash
40+ composer require jeremykenedy/laravel-exception-notifier:2.2.0
41+ ` ` `
42+
3743 Laravel 6 and below use:
3844
3945 ` ` ` bash
@@ -47,18 +53,36 @@ Uses package auto discovery feature, no need to edit the `config/app.php` file.
4753* Laravel 5.4 and below
4854Register the package with laravel in ` config/app.php` under ` providers` with the following:
4955
50- ` ` ` php
51- jeremykenedy\l aravelexceptionnotifier\L aravelExceptionNotifier::class,
52- ` ` `
56+ ` ` ` php
57+ jeremykenedy\l aravelexceptionnotifier\L aravelExceptionNotifier::class,
58+ ` ` `
5359
54603. Publish the packages view, mailer, and config files by running the following from your projects root folder:
5561
56- ` ` ` bash
57- php artisan vendor:publish --tag=laravelexceptionnotifier
58- ` ` `
62+ ` ` ` bash
63+ php artisan vendor:publish --tag=laravelexceptionnotifier
64+ ` ` `
65+
66+ # ### NOTE: If upgrading to Laravel 9 from an older version of this package you will need to republish the assets with:
67+
68+ ` ` ` bash
69+ php artisan vendor:publish --force --tag=laravelexceptionnotifier
70+ ` ` `
5971
60724. In ` App\E xceptions\H andler.php` include the additional following classes in the head:
6173
74+ # ### Laravel 9 and Above use:
75+
76+ ` ` ` php
77+ use App\M ail\E xceptionOccured;
78+ use Illuminate\F oundation\E xceptions\H andler as ExceptionHandler;
79+ use Illuminate\S upport\F acades\L og;
80+ use Mail;
81+ use Throwable;
82+ ` ` `
83+
84+ # ### Laravel 8 and Below use:
85+
6286` ` ` php
6387 use App\M ail\E xceptionOccured;
6488 use Illuminate\S upport\F acades\L og;
@@ -67,9 +91,29 @@ Register the package with laravel in `config/app.php` under `providers` with the
6791 use Symfony\C omponent\D ebug\E xceptionHandler as SymfonyExceptionHandler;
6892` ` `
6993
70- 5. In ` App\E xceptions\H andler.php` replace the `report ()` method with:
94+ 5. Update ` App\E xceptions\H andler.php`
95+
96+ # ### Laravel 9 and Above:
97+ # #### In `App\Exceptions\Handler.php` replace the `register()` method with:
98+
99+ ` ` ` php
100+ /**
101+ * Register the exception handling callbacks for the application.
102+ *
103+ * @return void
104+ * /
105+ public function register()
106+ {
107+ $this -> reportable(function (Throwable $e ) {
108+ $this -> sendEmail($e );
109+ });
110+ }
111+ ` ` `
112+
113+ # ### Laravel 8 and Below:
114+ # #### In `App\Exceptions\Handler.php` replace the `report()` method with:
71115
72- ` ` ` php
116+ ` ` ` php
73117 /**
74118 * Report or log an exception.
75119 *
@@ -93,11 +137,40 @@ Register the package with laravel in `config/app.php` under `providers` with the
93137
94138 parent::report($exception );
95139 }
96- ` ` `
140+ ` ` `
97141
981426. In ` App\E xceptions\H andler.php` add the method ` sendEmail()` :
99143
100- ` ` ` php
144+ # ### Laravel 9 and Above:
145+
146+ ` ` ` php
147+ /**
148+ * Sends an email upon exception.
149+ *
150+ * @param \T hrowable $exception
151+ *
152+ * @return void
153+ * /
154+ public function sendEmail(Throwable $exception )
155+ {
156+ try {
157+ $content [' message' ] = $exception->getMessage ();
158+ $content [' file' ] = $exception->getFile ();
159+ $content [' line' ] = $exception->getLine ();
160+ $content [' trace' ] = $exception->getTrace ();
161+ $content [' url' ] = request()->url ();
162+ $content [' body' ] = request()->all ();
163+ $content [' ip' ] = request()->ip ();
164+ Mail::send(new ExceptionOccured($content ));
165+ } catch (Throwable $exception ) {
166+ Log::error($exception );
167+ }
168+ }
169+ ` ` `
170+
171+ # ### Laravel 8 and Below:
172+
173+ ` ` ` php
101174 /**
102175 * Sends an email upon exception.
103176 *
@@ -117,22 +190,22 @@ Register the package with laravel in `config/app.php` under `providers` with the
117190 Log::error($exception );
118191 }
119192 }
120- ` ` `
193+ ` ` `
121194
1221957. Configure your email settings in the ` .env` file.
123196
1241978. Add the following (optional) settings to your ` .env` file and enter your settings:
125198
126199 * ** Note:** the defaults for these are located in ` config/exception.php`
127200
128- ` ` ` bash
201+ ` ` ` bash
129202 EMAIL_EXCEPTION_ENABLED=false
130203 EMAIL_EXCEPTION_FROM=" ${MAIL_FROM_ADDRESS} "
131204 EMAIL_EXCEPTION_TO=' email1@gmail.com, email2@gmail.com'
132205 EMAIL_EXCEPTION_CC=' '
133206 EMAIL_EXCEPTION_BCC=' '
134207 EMAIL_EXCEPTION_SUBJECT=' '
135- ` ` `
208+ ` ` `
136209
137210# # Screenshots
138211! [Email Notification](https://s3-us-west-2.amazonaws.com/github-project-images/laravel-exception-notifier/exception-error-email-min.jpeg)
0 commit comments