Skip to content

Commit 0bedb30

Browse files
committed
laravel7 updates
1 parent 5eb676b commit 0bedb30

File tree

4 files changed

+67
-53
lines changed

4 files changed

+67
-53
lines changed

.styleci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
preset: laravel
2+
3+
enabled:
4+
- strict
5+
- align_double_arrow
6+
7+
disabled:
8+
- unused_use

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2017-2019 <Jeremy Kenedy>
3+
Copyright (c) 2017-2020 <Jeremy Kenedy>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

readme.md

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Laravel Exception Notifier | A Laravel Exceptions Email Notification [Package](https://packagist.org/packages/jeremykenedy/laravel-exception-notifier)
1+
# Laravel Exception Notifier | A Laravel 5, 6, and 7 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)
@@ -21,15 +21,23 @@ Laravel exception notifier will send an email of the error along with the stack
2121
Get the errors and fix them before the client even reports them, that's why this exists!
2222

2323
## Requirements
24-
* [Laravel 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8+](https://laravel.com/docs/installation)
24+
* [Laravel 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6, & 7+](https://laravel.com/docs/installation)
2525

2626
## Installation Instructions
2727
1. From your projects root folder in terminal run:
2828

29+
Laravel 7+ use:
30+
2931
```
3032
composer require jeremykenedy/laravel-exception-notifier
3133
```
3234
35+
Laravel 6 and below use:
36+
37+
```
38+
composer require jeremykenedy/laravel-exception-notifier:1.2.0
39+
```
40+
3341
2. Register the package
3442
* Laravel 5.5 and up
3543
Uses package auto discovery feature, no need to edit the `config/app.php` file.
@@ -47,69 +55,66 @@ Register the package with laravel in `config/app.php` under `providers` with the
4755
php artisan vendor:publish --tag=laravelexceptionnotifier
4856
```
4957
50-
4. In `App\Exceptions\Handler.php` include the following classes in the head:
58+
4. In `App\Exceptions\Handler.php` include the additional following classes in the head:
5159
5260
```
5361
use App\Mail\ExceptionOccured;
5462
use Illuminate\Support\Facades\Log;
5563
use Mail;
56-
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
5764
use Symfony\Component\Debug\Exception\FlattenException;
65+
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
5866
```
5967
6068
5. In `App\Exceptions\Handler.php` replace the `report()` method with:
6169
6270
```
63-
/**
64-
* Report or log an exception.
65-
*
66-
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
67-
*
68-
* @param \Exception $exception
69-
* @return void
70-
*/
71-
public function report(Exception $exception)
72-
{
73-
74-
$enableEmailExceptions = config('exceptions.emailExceptionEnabled');
75-
76-
if ($enableEmailExceptions === "") {
77-
$enableEmailExceptions = config('exceptions.emailExceptionEnabledDefault');
78-
}
79-
80-
if ($enableEmailExceptions && $this->shouldReport($exception)) {
81-
$this->sendEmail($exception);
82-
}
83-
84-
parent::report($exception);
71+
/**
72+
* Report or log an exception.
73+
*
74+
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
75+
*
76+
* @param \Throwable $exception
77+
*
78+
* @return void
79+
*/
80+
public function report(Throwable $exception)
81+
{
82+
$enableEmailExceptions = config('exceptions.emailExceptionEnabled');
83+
84+
if ($enableEmailExceptions === '') {
85+
$enableEmailExceptions = config('exceptions.emailExceptionEnabledDefault');
8586
}
86-
```
8787
88-
6. In `App\Exceptions\Handler.php` add the method `sendEmail()`:
88+
if ($enableEmailExceptions && $this->shouldReport($exception)) {
89+
$this->sendEmail($exception);
90+
}
8991
92+
parent::report($exception);
93+
}
9094
```
91-
/**
92-
* Sends an email upon exception.
93-
*
94-
* @param \Exception $exception
95-
* @return void
96-
*/
97-
public function sendEmail(Exception $exception)
98-
{
99-
try {
100-
101-
$e = FlattenException::create($exception);
102-
$handler = new SymfonyExceptionHandler();
103-
$html = $handler->getHtml($e);
104-
105-
Mail::send(new ExceptionOccured($html));
10695
107-
} catch (Exception $exception) {
108-
109-
Log::error($exception);
96+
6. In `App\Exceptions\Handler.php` add the method `sendEmail()`:
11097
111-
}
98+
```
99+
/**
100+
* Sends an email upon exception.
101+
*
102+
* @param \Throwable $exception
103+
*
104+
* @return void
105+
*/
106+
public function sendEmail(Throwable $exception)
107+
{
108+
try {
109+
$e = FlattenException::create($exception);
110+
$handler = new SymfonyExceptionHandler();
111+
$html = $handler->getHtml($e);
112+
113+
Mail::send(new ExceptionOccured($html));
114+
} catch (Throwable $exception) {
115+
Log::error($exception);
112116
}
117+
}
113118
```
114119
115120
7. Configure your email settings in the `.env` file.

src/App/Traits/ExceptionNotificationHandlerTrait.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Mail;
88
use Symfony\Component\Debug\Exception\FlattenException;
99
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
10+
use Throwable;
1011

1112
trait ExceptionNotificationHandlerTrait
1213
{
@@ -29,11 +30,11 @@ trait ExceptionNotificationHandlerTrait
2930
*
3031
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
3132
*
32-
* @param \Exception $exception
33+
* @param \Throwable $exception
3334
*
3435
* @return void
3536
*/
36-
public function report(Exception $exception)
37+
public function report(Throwable $exception)
3738
{
3839
$enableEmailExceptions = config('exceptions.emailExceptionEnabled');
3940

@@ -53,19 +54,19 @@ public function report(Exception $exception)
5354
/**
5455
* Sends an email upon exception.
5556
*
56-
* @param \Exception $exception
57+
* @param \Throwable $exception
5758
*
5859
* @return void
5960
*/
60-
public function sendEmail(Exception $exception)
61+
public function sendEmail(Throwable $exception)
6162
{
6263
try {
6364
$e = FlattenException::create($exception);
6465
$handler = new SymfonyExceptionHandler();
6566
$html = $handler->getHtml($e);
6667

6768
Mail::send(new ExceptionOccured($html));
68-
} catch (Exception $exception) {
69+
} catch (Throwable $exception) {
6970
Log::error($exception);
7071
}
7172
}

0 commit comments

Comments
 (0)