Skip to content

Commit 20dc91f

Browse files
committed
doc: Update README for Laravel 10
1 parent 3edf744 commit 20dc91f

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

readme.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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\Traits\ExceptionNotificationHandlerTrait;
80+
use App\Mail\ExceptionOccurred;
81+
use Illuminate\Support\Facades\Log;
82+
use Illuminate\Support\Facades\Mail;
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

Comments
 (0)