Skip to content

Commit b56d851

Browse files
authored
Merge pull request #13 from DevDavido/laravel-10
feat: Provide Laravel 10 support
2 parents 02217d7 + cf0df06 commit b56d851

8 files changed

+147
-171
lines changed

Diff for: .travis.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
1+
22
language: php
33
sudo: required
44
dist: trusty
55
group: edge
66

77
php:
8-
- 7.2.5
9-
- 7.3
10-
- 7.4
8+
- 8.0
9+
- 8.1
10+
- 8.2
1111

1212
sudo: false
1313

@@ -16,7 +16,7 @@ services:
1616

1717
before_script:
1818
- mysql -u root -e 'create database laravelexceptionnotifier;'
19-
- curl -s http://getcomposer.org/installer | php
19+
- curl -s https://getcomposer.org/installer | php
2020
- php composer.phar install
2121
- composer create-project --prefer-dist laravel/laravel laravelexceptionnotifier
2222
- cp .env.travis laravelexceptionnotifier/.env

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"php": "^8.0"
2727
},
2828
"require-dev": {
29-
"laravel/framework": "9.*"
29+
"laravel/framework": "9.*|10.*"
3030
},
3131
"autoload": {
3232
"psr-4": {

Diff for: readme.md

+48-48
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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)
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)
@@ -18,17 +18,20 @@ Table of contents:
1818
- [License](#license)
1919

2020
## 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.
2225

2326
Get the errors and fix them before the client even reports them, that's why this exists!
2427

2528
## 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)
2730

2831
## Installation Instructions
2932
1. From your projects root folder in terminal run:
3033

31-
Laravel 9+ use:
34+
Laravel 9-10 use:
3235

3336
```bash
3437
composer require jeremykenedy/laravel-exception-notifier
@@ -63,7 +66,7 @@ Register the package with laravel in `config/app.php` under `providers` with the
6366
php artisan vendor:publish --tag=laravelexceptionnotifier
6467
```
6568

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:
6770

6871
```bash
6972
php artisan vendor:publish --force --tag=laravelexceptionnotifier
@@ -74,10 +77,9 @@ Register the package with laravel in `config/app.php` under `providers` with the
7477
#### Laravel 9 and Above use:
7578

7679
```php
77-
use App\Mail\ExceptionOccured;
78-
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
80+
use App\Mail\ExceptionOccurred;
7981
use Illuminate\Support\Facades\Log;
80-
use Mail;
82+
use Illuminate\Support\Facades\Mail;
8183
use Throwable;
8284
```
8385

@@ -94,24 +96,52 @@ Register the package with laravel in `config/app.php` under `providers` with the
9496
5. Update `App\Exceptions\Handler.php`
9597

9698
#### Laravel 9 and Above:
97-
##### In `App\Exceptions\Handler.php` replace the `register()` method with:
9899

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:
99126
```php
100127
/**
101128
* Register the exception handling callbacks for the application.
102-
*
103-
* @return void
104129
*/
105-
public function register()
130+
public function register(): void
106131
{
107132
$this->reportable(function (Throwable $e) {
108-
$this->sendEmail($e);
133+
$enableEmailExceptions = config('exceptions.emailExceptionEnabled');
134+
135+
if ($enableEmailExceptions) {
136+
$this->sendEmail($e);
137+
}
109138
});
110139
}
111140
```
112141
113142
#### Laravel 8 and Below:
114-
##### In `App\Exceptions\Handler.php` replace the `report()` method with:
143+
144+
##### Replace the `report()` method with:
115145
116146
```php
117147
/**
@@ -139,37 +169,7 @@ Register the package with laravel in `config/app.php` under `providers` with the
139169
}
140170
```
141171
142-
6. In `App\Exceptions\Handler.php` add the method `sendEmail()`:
143-
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-
172+
##### Add the method `sendEmail()`:
173173
```php
174174
/**
175175
* Sends an email upon exception.
@@ -192,9 +192,9 @@ Register the package with laravel in `config/app.php` under `providers` with the
192192
}
193193
```
194194
195-
7. Configure your email settings in the `.env` file.
195+
6. Configure your email settings in the `.env` file.
196196
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:
198198
199199
* **Note:** the defaults for these are located in `config/exception.php`
200200
@@ -221,7 +221,7 @@ Register the package with laravel in `config/app.php` under `providers` with the
221221
├── .env.example
222222
├── App
223223
│   ├── Mail
224-
│   │   └── ExceptionOccured.php
224+
│   │   └── ExceptionOccurred.php
225225
│   └── Traits
226226
│   └── ExceptionNotificationHandlerTrait.php
227227
├── LaravelExceptionNotifier.php

Diff for: src/App/Mail/ExceptionOccured.php

-66
This file was deleted.

Diff for: src/App/Mail/ExceptionOccurred.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace App\Mail;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Mail\Mailable;
7+
use Illuminate\Mail\Mailables\Content;
8+
use Illuminate\Mail\Mailables\Envelope;
9+
use Illuminate\Queue\SerializesModels;
10+
11+
class ExceptionOccurred extends Mailable
12+
{
13+
use Queueable, SerializesModels;
14+
15+
private array $content;
16+
17+
/**
18+
* Create a new message instance.
19+
*/
20+
public function __construct($content)
21+
{
22+
$this->content = $content;
23+
}
24+
25+
/**
26+
* Get the message envelope.
27+
*/
28+
public function envelope(): Envelope
29+
{
30+
$emailsTo = config('exceptions.emailExceptionsTo', false) ?
31+
str_getcsv(config('exceptions.emailExceptionsTo')) :
32+
null;
33+
$emailsCc = config('exceptions.emailExceptionCCto', false) ?
34+
str_getcsv(config('exceptions.emailExceptionCCto')) :
35+
null;
36+
$emailsBcc = config('exceptions.emailExceptionBCCto', false) ?
37+
str_getcsv(config('exceptions.emailExceptionBCCto')) :
38+
null;
39+
$fromSender = config('exceptions.emailExceptionFrom');
40+
$subject = config('exceptions.emailExceptionSubject');
41+
42+
return new Envelope(
43+
from: $fromSender,
44+
to: $emailsTo,
45+
cc: $emailsCc,
46+
bcc: $emailsBcc,
47+
subject: $subject
48+
);
49+
}
50+
51+
/**
52+
* Get the message content definition.
53+
*/
54+
public function content(): Content
55+
{
56+
$view = config('exceptions.emailExceptionView');
57+
58+
return new Content(
59+
view: $view,
60+
with: [
61+
'content' => $this->content,
62+
]
63+
);
64+
}
65+
}

0 commit comments

Comments
 (0)