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 )
2
2
3
3
[ ![ Total Downloads] ( https://poser.pugx.org/jeremykenedy/laravel-exception-notifier/d/total.svg )] ( https://packagist.org/packages/jeremykenedy/laravel-exception-notifier )
4
4
[ ![ 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
28
28
## Installation Instructions
29
29
1 . From your projects root folder in terminal run:
30
30
31
- Laravel 7 + use:
31
+ Laravel 9 + use:
32
32
33
33
``` bash
34
34
composer require jeremykenedy/laravel-exception-notifier
35
35
```
36
36
37
+ Laravel 7-8 use:
38
+
39
+ ` ` ` bash
40
+ composer require jeremykenedy/laravel-exception-notifier:2.2.0
41
+ ` ` `
42
+
37
43
Laravel 6 and below use:
38
44
39
45
` ` ` bash
@@ -47,18 +53,36 @@ Uses package auto discovery feature, no need to edit the `config/app.php` file.
47
53
* Laravel 5.4 and below
48
54
Register the package with laravel in ` config/app.php` under ` providers` with the following:
49
55
50
- ` ` ` php
51
- jeremykenedy\l aravelexceptionnotifier\L aravelExceptionNotifier::class,
52
- ` ` `
56
+ ` ` ` php
57
+ jeremykenedy\l aravelexceptionnotifier\L aravelExceptionNotifier::class,
58
+ ` ` `
53
59
54
60
3. Publish the packages view, mailer, and config files by running the following from your projects root folder:
55
61
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
+ ` ` `
59
71
60
72
4. In ` App\E xceptions\H andler.php` include the additional following classes in the head:
61
73
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
+
62
86
` ` ` php
63
87
use App\M ail\E xceptionOccured;
64
88
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
67
91
use Symfony\C omponent\D ebug\E xceptionHandler as SymfonyExceptionHandler;
68
92
` ` `
69
93
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:
71
115
72
- ` ` ` php
116
+ ` ` ` php
73
117
/**
74
118
* Report or log an exception.
75
119
*
@@ -93,11 +137,40 @@ Register the package with laravel in `config/app.php` under `providers` with the
93
137
94
138
parent::report($exception );
95
139
}
96
- ` ` `
140
+ ` ` `
97
141
98
142
6. In ` App\E xceptions\H andler.php` add the method ` sendEmail()` :
99
143
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
101
174
/**
102
175
* Sends an email upon exception.
103
176
*
@@ -117,22 +190,22 @@ Register the package with laravel in `config/app.php` under `providers` with the
117
190
Log::error($exception );
118
191
}
119
192
}
120
- ` ` `
193
+ ` ` `
121
194
122
195
7. Configure your email settings in the ` .env` file.
123
196
124
197
8. Add the following (optional) settings to your ` .env` file and enter your settings:
125
198
126
199
* ** Note:** the defaults for these are located in ` config/exception.php`
127
200
128
- ` ` ` bash
201
+ ` ` ` bash
129
202
EMAIL_EXCEPTION_ENABLED=false
130
203
EMAIL_EXCEPTION_FROM=" ${MAIL_FROM_ADDRESS} "
131
204
132
205
EMAIL_EXCEPTION_CC=' '
133
206
EMAIL_EXCEPTION_BCC=' '
134
207
EMAIL_EXCEPTION_SUBJECT=' '
135
- ` ` `
208
+ ` ` `
136
209
137
210
# # Screenshots
138
211
! [Email Notification](https://s3-us-west-2.amazonaws.com/github-project-images/laravel-exception-notifier/exception-error-email-min.jpeg)
0 commit comments