1
- # Laravel Exception Notifier | A Laravel 5, 6, 7, 8, and 9 Exceptions Email Notification [ Package] ( https://packagist.org/packages/jeremykenedy/laravel-exception-notifier )
1
+ # Laravel Exception Notifier | A Laravel 5, 6, 7, 8, 9 and 10 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 )
@@ -18,17 +18,20 @@ Table of contents:
18
18
- [ License] ( #license )
19
19
20
20
## About
21
- Laravel exception notifier will send an email of the error along with the stack trace to the chosen recipients. [ This Package] ( https://packagist.org/packages/jeremykenedy/laravel-exception-notifier ) includes all necessary traits, views, configs, and Mailers for email notifications upon your applications exceptions. You can customize who send to, cc to, bcc to, enable/disable, and custom subject or default subject based on environment. Built for Laravel 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6, 7, 8, and 9+.
21
+ Laravel exception notifier will send an email of the error along with the stack trace to the chosen recipients.
22
+ [ This Package] ( https://packagist.org/packages/jeremykenedy/laravel-exception-notifier ) includes all necessary traits, views, configs, and Mailers for email notifications upon your applications exceptions.
23
+ You can customize who send to, cc to, bcc to, enable/disable, and custom subject or default subject based on environment.
24
+ Built for Laravel 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6, 7, 8, 9, and 10.
22
25
23
26
Get the errors and fix them before the client even reports them, that's why this exists!
24
27
25
28
## Requirements
26
- * [ Laravel 5.2+, 6, 7, 8, or 9+ ] ( https://laravel.com/docs/installation )
29
+ * [ Laravel 5.2+, 6, 7, 8, 9, or 10 ] ( https://laravel.com/docs/installation )
27
30
28
31
## Installation Instructions
29
32
1 . From your projects root folder in terminal run:
30
33
31
- Laravel 9+ use:
34
+ Laravel 9-10 use:
32
35
33
36
``` bash
34
37
composer require jeremykenedy/laravel-exception-notifier
@@ -63,7 +66,7 @@ Register the package with laravel in `config/app.php` under `providers` with the
63
66
php artisan vendor:publish --tag=laravelexceptionnotifier
64
67
` ` `
65
68
66
- # ### NOTE: If upgrading to Laravel 9 from an older version of this package you will need to republish the assets with:
69
+ # ### NOTE: If upgrading to Laravel 9 or 10 from an older version of this package you will need to republish the assets with:
67
70
68
71
` ` ` bash
69
72
php artisan vendor:publish --force --tag=laravelexceptionnotifier
@@ -74,10 +77,9 @@ Register the package with laravel in `config/app.php` under `providers` with the
74
77
# ### Laravel 9 and Above use:
75
78
76
79
` ` ` php
77
- use App\M ail\E xceptionOccured;
78
- use Illuminate\F oundation\E xceptions\H andler as ExceptionHandler;
80
+ use App\M ail\E xceptionOccurred;
79
81
use Illuminate\S upport\F acades\L og;
80
- use Mail;
82
+ use Illuminate \S upport \F acades \ M ail;
81
83
use Throwable;
82
84
` ` `
83
85
@@ -94,24 +96,52 @@ Register the package with laravel in `config/app.php` under `providers` with the
94
96
5. Update ` App\E xceptions\H andler.php`
95
97
96
98
# ### Laravel 9 and Above:
97
- # #### In `App\Exceptions\Handler.php` replace the `register()` method with:
98
99
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:
99
126
` ` ` php
100
127
/**
101
128
* Register the exception handling callbacks for the application.
102
- *
103
- * @return void
104
129
* /
105
- public function register()
130
+ public function register(): void
106
131
{
107
132
$this -> reportable(function (Throwable $e ) {
108
- $this -> sendEmail($e );
133
+ $enableEmailExceptions = config(' exceptions.emailExceptionEnabled' );
134
+
135
+ if ($enableEmailExceptions ) {
136
+ $this -> sendEmail($e );
137
+ }
109
138
});
110
139
}
111
140
` ` `
112
141
113
142
# ### Laravel 8 and Below:
114
- # #### In `App\Exceptions\Handler.php` replace the `report()` method with:
143
+
144
+ # #### Replace the `report()` method with:
115
145
116
146
` ` ` php
117
147
/**
@@ -139,37 +169,7 @@ Register the package with laravel in `config/app.php` under `providers` with the
139
169
}
140
170
` ` `
141
171
142
- 6. In ` App\E xceptions\H andler.php` add the method ` sendEmail()` :
143
-
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
-
172
+ # #### Add the method `sendEmail()`:
173
173
` ` ` php
174
174
/**
175
175
* Sends an email upon exception.
@@ -192,9 +192,9 @@ Register the package with laravel in `config/app.php` under `providers` with the
192
192
}
193
193
` ` `
194
194
195
- 7 . Configure your email settings in the ` .env` file.
195
+ 6 . Configure your email settings in the ` .env` file.
196
196
197
- 8 . Add the following (optional) settings to your ` .env` file and enter your settings:
197
+ 7 . Add the following (optional) settings to your ` .env` file and enter your settings:
198
198
199
199
* ** Note:** the defaults for these are located in ` config/exception.php`
200
200
@@ -221,7 +221,7 @@ Register the package with laravel in `config/app.php` under `providers` with the
221
221
├── .env.example
222
222
├── App
223
223
│ ├── Mail
224
- │ │ └── ExceptionOccured .php
224
+ │ │ └── ExceptionOccurred .php
225
225
│ └── Traits
226
226
│ └── ExceptionNotificationHandlerTrait.php
227
227
├── LaravelExceptionNotifier.php
0 commit comments