-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from jeremykenedy/laravel7
Laravel7
- Loading branch information
Showing
9 changed files
with
103 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{yml,yaml}] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,4 +50,3 @@ packages/ | |
# Debug Files | ||
npm-debug.log | ||
yarn-error.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
preset: laravel | ||
|
||
enabled: | ||
- strict | ||
- align_double_arrow | ||
|
||
disabled: | ||
- unused_use |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Laravel Exception Notifier | A Laravel Exceptions Email Notification [Package](https://packagist.org/packages/jeremykenedy/laravel-exception-notifier) | ||
# Laravel Exception Notifier | A Laravel 5, 6, and 7 Exceptions Email Notification [Package](https://packagist.org/packages/jeremykenedy/laravel-exception-notifier) | ||
|
||
[![Total Downloads](https://poser.pugx.org/jeremykenedy/laravel-exception-notifier/d/total.svg)](https://packagist.org/packages/jeremykenedy/laravel-exception-notifier) | ||
[![Latest Stable Version](https://poser.pugx.org/jeremykenedy/laravel-exception-notifier/v/stable.svg)](https://packagist.org/packages/jeremykenedy/laravel-exception-notifier) | ||
|
@@ -16,100 +16,105 @@ Table of contents: | |
- [License](#license) | ||
|
||
## About | ||
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, and 5.8+. | ||
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, and 7+. | ||
|
||
Get the errors and fix them before the client even reports them, that's why this exists! | ||
|
||
## Requirements | ||
* [Laravel 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8+](https://laravel.com/docs/installation) | ||
* [Laravel 5.2+, 6, or 7+](https://laravel.com/docs/installation) | ||
|
||
## Installation Instructions | ||
1. From your projects root folder in terminal run: | ||
|
||
``` | ||
Laravel 7+ use: | ||
|
||
```bash | ||
composer require jeremykenedy/laravel-exception-notifier | ||
``` | ||
|
||
Laravel 6 and below use: | ||
|
||
```bash | ||
composer require jeremykenedy/laravel-exception-notifier:1.2.0 | ||
``` | ||
|
||
2. Register the package | ||
* Laravel 5.5 and up | ||
Uses package auto discovery feature, no need to edit the `config/app.php` file. | ||
|
||
* Laravel 5.4 and below | ||
Register the package with laravel in `config/app.php` under `providers` with the following: | ||
|
||
``` | ||
```php | ||
jeremykenedy\laravelexceptionnotifier\LaravelExceptionNotifier::class, | ||
``` | ||
|
||
3. Publish the packages view, mailer, and config files by running the following from your projects root folder: | ||
|
||
``` | ||
```bash | ||
php artisan vendor:publish --tag=laravelexceptionnotifier | ||
``` | ||
|
||
4. In `App\Exceptions\Handler.php` include the following classes in the head: | ||
4. In `App\Exceptions\Handler.php` include the additional following classes in the head: | ||
|
||
``` | ||
```php | ||
use App\Mail\ExceptionOccured; | ||
use Illuminate\Support\Facades\Log; | ||
use Mail; | ||
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler; | ||
use Symfony\Component\Debug\Exception\FlattenException; | ||
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler; | ||
``` | ||
|
||
5. In `App\Exceptions\Handler.php` replace the `report()` method with: | ||
``` | ||
/** | ||
* Report or log an exception. | ||
* | ||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. | ||
* | ||
* @param \Exception $exception | ||
* @return void | ||
*/ | ||
public function report(Exception $exception) | ||
{ | ||
$enableEmailExceptions = config('exceptions.emailExceptionEnabled'); | ||
if ($enableEmailExceptions === "") { | ||
$enableEmailExceptions = config('exceptions.emailExceptionEnabledDefault'); | ||
} | ||
if ($enableEmailExceptions && $this->shouldReport($exception)) { | ||
$this->sendEmail($exception); | ||
} | ||
parent::report($exception); | ||
```php | ||
/** | ||
* Report or log an exception. | ||
* | ||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. | ||
* | ||
* @param \Throwable $exception | ||
* | ||
* @return void | ||
*/ | ||
public function report(Throwable $exception) | ||
{ | ||
$enableEmailExceptions = config('exceptions.emailExceptionEnabled'); | ||
|
||
if ($enableEmailExceptions === '') { | ||
$enableEmailExceptions = config('exceptions.emailExceptionEnabledDefault'); | ||
} | ||
``` | ||
|
||
6. In `App\Exceptions\Handler.php` add the method `sendEmail()`: | ||
if ($enableEmailExceptions && $this->shouldReport($exception)) { | ||
$this->sendEmail($exception); | ||
} | ||
|
||
parent::report($exception); | ||
} | ||
``` | ||
/** | ||
* Sends an email upon exception. | ||
* | ||
* @param \Exception $exception | ||
* @return void | ||
*/ | ||
public function sendEmail(Exception $exception) | ||
{ | ||
try { | ||
$e = FlattenException::create($exception); | ||
$handler = new SymfonyExceptionHandler(); | ||
$html = $handler->getHtml($e); | ||
Mail::send(new ExceptionOccured($html)); | ||
} catch (Exception $exception) { | ||
Log::error($exception); | ||
6. In `App\Exceptions\Handler.php` add the method `sendEmail()`: | ||
} | ||
```php | ||
/** | ||
* Sends an email upon exception. | ||
* | ||
* @param \Throwable $exception | ||
* | ||
* @return void | ||
*/ | ||
public function sendEmail(Throwable $exception) | ||
{ | ||
try { | ||
$e = FlattenException::create($exception); | ||
$handler = new SymfonyExceptionHandler(); | ||
$html = $handler->getHtml($e); | ||
|
||
Mail::send(new ExceptionOccured($html)); | ||
} catch (Throwable $exception) { | ||
Log::error($exception); | ||
} | ||
} | ||
``` | ||
7. Configure your email settings in the `.env` file. | ||
|
@@ -118,9 +123,9 @@ Register the package with laravel in `config/app.php` under `providers` with the | |
* **Note:** the defaults for these are located in `config/exception.php` | ||
``` | ||
```bash | ||
EMAIL_EXCEPTION_ENABLED=false | ||
EMAIL_EXCEPTION_FROM='[email protected]' | ||
EMAIL_EXCEPTION_FROM="${MAIL_FROM_ADDRESS}" | ||
EMAIL_EXCEPTION_TO='[email protected], [email protected]' | ||
EMAIL_EXCEPTION_CC='' | ||
EMAIL_EXCEPTION_BCC='' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters