Skip to content

Commit 96b6bc2

Browse files
authored
Merge pull request #8 from jeremykenedy/l9
update for Laravel 9
2 parents 97b448d + 07212ae commit 96b6bc2

File tree

3 files changed

+171
-18
lines changed

3 files changed

+171
-18
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
}
2424
],
2525
"require": {
26-
"php": "^7.2|^8.0"
26+
"php": "^8.0"
2727
},
2828
"require-dev": {
2929
"illuminate/support": "^6.0.2",
3030
"orchestra/testbench": "^3.8.5",
3131
"phpunit/phpunit": "^8.3.4",
32-
"laravel/framework": "6.*|7.*|8.*"
32+
"laravel/framework": "9.*"
3333
},
3434
"autoload": {
3535
"psr-4": {

readme.md

+88-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
2929
1. 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
4854
Register the package with laravel in `config/app.php` under `providers` with the following:
4955

50-
```php
51-
jeremykenedy\laravelexceptionnotifier\LaravelExceptionNotifier::class,
52-
```
56+
```php
57+
jeremykenedy\laravelexceptionnotifier\LaravelExceptionNotifier::class,
58+
```
5359

5460
3. 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

6072
4. In `App\Exceptions\Handler.php` include the additional following classes in the head:
6173

74+
#### Laravel 9 and Above use:
75+
76+
```php
77+
use App\Mail\ExceptionOccured;
78+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
79+
use Illuminate\Support\Facades\Log;
80+
use Mail;
81+
use Throwable;
82+
```
83+
84+
#### Laravel 8 and Below use:
85+
6286
```php
6387
use App\Mail\ExceptionOccured;
6488
use Illuminate\Support\Facades\Log;
@@ -67,9 +91,29 @@ Register the package with laravel in `config/app.php` under `providers` with the
6791
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
6892
```
6993

70-
5. In `App\Exceptions\Handler.php` replace the `report()` method with:
94+
5. Update `App\Exceptions\Handler.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
98142
6. In `App\Exceptions\Handler.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 \Throwable $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
122195
7. Configure your email settings in the `.env` file.
123196
124197
8. 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='[email protected], [email protected]'
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)
Original file line numberDiff line numberDiff line change
@@ -1 +1,81 @@
1-
{!! $content !!}
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="robots" content="noindex,nofollow" />
6+
<style>
7+
body { background-color: #F9F9F9; color: #222; font: 14px/1.4 Helvetica, Arial, sans-serif; margin: 0; padding-bottom: 45px; }
8+
a { cursor: pointer; text-decoration: none; }
9+
a:hover { text-decoration: underline; }
10+
abbr[title] { border-bottom: none; cursor: help; text-decoration: none; }
11+
code, pre { font: 13px/1.5 Consolas, Monaco, Menlo, "Ubuntu Mono", "Liberation Mono", monospace; }
12+
table, tr, th, td { background: #FFF; border-collapse: collapse; vertical-align: top; }
13+
table { background: #FFF; border: 1px solid #E0E0E0; box-shadow: 0px 0px 1px rgba(128, 128, 128, .2); margin: 1em 0; width: 100%; }
14+
table th, table td { border: solid #E0E0E0; border-width: 1px 0; padding: 8px 10px; }
15+
table th { background-color: #E0E0E0; font-weight: bold; text-align: left; }
16+
.hidden-xs-down { display: none; }
17+
.block { display: block; }
18+
.break-long-words { -ms-word-break: break-all; word-break: break-all; word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; }
19+
.text-muted { color: #999; }
20+
.container { max-width: 1024px; margin: 0 auto; padding: 0 15px; }
21+
.container::after { content: ""; display: table; clear: both; }
22+
.exception-summary { background: #B0413E; border-bottom: 2px solid rgba(0, 0, 0, 0.1); border-top: 1px solid rgba(0, 0, 0, .3); flex: 0 0 auto; margin-bottom: 30px; }
23+
.exception-message-wrapper { display: flex; align-items: center; min-height: 70px; }
24+
.exception-message { flex-grow: 1; padding: 30px 0; }
25+
.exception-message, .exception-message a { color: #FFF; font-size: 21px; font-weight: 400; margin: 0; }
26+
.exception-message.long { font-size: 18px; }
27+
.exception-message a { border-bottom: 1px solid rgba(255, 255, 255, 0.5); font-size: inherit; text-decoration: none; }
28+
.exception-message a:hover { border-bottom-color: #ffffff; }
29+
.exception-illustration { flex-basis: 111px; flex-shrink: 0; height: 66px; margin-left: 15px; opacity: .7; }
30+
.trace + .trace { margin-top: 30px; }
31+
.trace-head .trace-class { color: #222; font-size: 18px; font-weight: bold; line-height: 1.3; margin: 0; position: relative; }
32+
.trace-message { font-size: 14px; font-weight: normal; margin: .5em 0 0; }
33+
.trace-file-path, .trace-file-path a { color: #222; margin-top: 3px; font-size: 13px; }
34+
.trace-class { color: #B0413E; }
35+
.trace-type { padding: 0 2px; }
36+
.trace-method { color: #B0413E; font-weight: bold; }
37+
.trace-arguments { color: #777; font-weight: normal; padding-left: 2px; }
38+
@media (min-width: 575px) {
39+
.hidden-xs-down { display: initial; }
40+
}</style>
41+
</head>
42+
<body>
43+
<div class="exception-summary">
44+
<div class="container">
45+
<div class="exception-message-wrapper">
46+
<h1 class="break-long-words exception-message">{{ $content['message'] ?? '' }}</h1>
47+
<div class="exception-illustration hidden-xs-down"></div>
48+
</div>
49+
</div>
50+
</div>
51+
<div class="container">
52+
<div class="trace trace-as-html">
53+
<table class="trace-details">
54+
<thead class="trace-head"><tr><th>
55+
<h3 class="trace-class">
56+
<span class="text-muted">(1/1)</span>
57+
<span class="exception_title"><span title="ErrorException">ErrorException</span></span>
58+
</h3>
59+
<p class="break-long-words trace-message">{{ $content['message'] ?? '' }}</p>
60+
<p class="">URL: {{ $content['url'] ?? '' }}</p>
61+
<p class="">IP: {{ $content['ip'] ?? '' }}</p>
62+
</th></tr></thead>
63+
<tbody>
64+
<tr>
65+
<td>
66+
<span class="block trace-file-path">in <span title="{{ $content['file'] ?? '' }}"><strong>{{ $content['file'] ?? '' }}</strong> line {{ $content['line'] ?? '' }}</span></span>
67+
</td>
68+
</tr>
69+
@foreach(($content['trace'] ?? []) as $value)
70+
<tr>
71+
<td>
72+
at <span class="trace-class"><span title="{{ $value['class'] ?? '' }}">{{ basename($value['class'] ?? '') }}</span></span><span class="trace-type">-></span><span class="trace-method">{{ $value['function'] ?? '' }}</span>(<span class="trace-arguments"></span>)<span class="block trace-file-path">in <span title=""><strong>{{ $value['file'] ?? '' }}</strong> line {{ $value['line'] ?? '' }}</span></span>
73+
</td>
74+
</tr>
75+
@endforeach
76+
</tbody>
77+
</table>
78+
</div>
79+
</div>
80+
</body>
81+
</html>

0 commit comments

Comments
 (0)