Skip to content

Commit

Permalink
Merge pull request #4 from jeremykenedy/laravel7
Browse files Browse the repository at this point in the history
Laravel7
  • Loading branch information
jeremykenedy authored Mar 30, 2020
2 parents 5eb676b + 31f1594 commit d51fc63
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 75 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ packages/
# Debug Files
npm-debug.log
yarn-error.log

8 changes: 8 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
preset: laravel

enabled:
- strict
- align_double_arrow

disabled:
- unused_use
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ dist: trusty
group: edge

php:
- 7.1
- 7.2
- 7.2.5
- 7.3

sudo: false
Expand All @@ -26,7 +25,8 @@ before_script:
- composer require jeremykenedy/laravel-exception-notifier
- php artisan key:generate
- php artisan vendor:publish --tag=laravelexceptionnotifier
- php artisan make:auth
- composer require laravel/ui --dev
- php artisan ui vue --auth
- composer dump-autoload
- php artisan clear-compiled

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

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

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
}
],
"require": {
"php": ">=7.1.3"
"php": "^7.2",
},
"require-dev": {
"illuminate/support": "^5.8",
"orchestra/testbench": "~3.0",
"phpunit/phpunit": "^7.5",
"laravel/laravel": "5.8.*"
"illuminate/support": "^6.0.2",
"orchestra/testbench": "^3.8.5",
"phpunit/phpunit": "^8.3.4",
"laravel/framework": "6.*|7.*"
},
"autoload": {
"psr-4": {
Expand Down
115 changes: 60 additions & 55 deletions readme.md
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)
Expand All @@ -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.
Expand All @@ -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=''
Expand Down
10 changes: 5 additions & 5 deletions src/App/Mail/ExceptionOccured.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ public function build()
$fromSender = config('exceptions.emailExceptionFrom');
$subject = config('exceptions.emailExceptionSubject');

if ($emailsTo[0] == null) {
if ($emailsTo[0] === null) {
$emailsTo = config('exceptions.emailExceptionsToDefault');
}

if ($ccEmails[0] == null) {
if ($ccEmails[0] === null) {
$ccEmails = config('exceptions.emailExceptionCCtoDefault');
}

if ($bccEmails[0] == null) {
if ($bccEmails[0] === null) {
$bccEmails = config('exceptions.emailExceptionBCCtoDefault');
}

if (!$fromSender) {
if (! $fromSender) {
$fromSender = config('exceptions.emailExceptionFromDefault');
}

if (!$subject) {
if (! $subject) {
$subject = config('exceptions.emailExceptionSubjectDefault');
}

Expand Down
11 changes: 6 additions & 5 deletions src/App/Traits/ExceptionNotificationHandlerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Mail;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
use Throwable;

trait ExceptionNotificationHandlerTrait
{
Expand All @@ -29,11 +30,11 @@ trait ExceptionNotificationHandlerTrait
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @param \Throwable $exception
*
* @return void
*/
public function report(Exception $exception)
public function report(Throwable $exception)
{
$enableEmailExceptions = config('exceptions.emailExceptionEnabled');

Expand All @@ -53,19 +54,19 @@ public function report(Exception $exception)
/**
* Sends an email upon exception.
*
* @param \Exception $exception
* @param \Throwable $exception
*
* @return void
*/
public function sendEmail(Exception $exception)
public function sendEmail(Throwable $exception)
{
try {
$e = FlattenException::create($exception);
$handler = new SymfonyExceptionHandler();
$html = $handler->getHtml($e);

Mail::send(new ExceptionOccured($html));
} catch (Exception $exception) {
} catch (Throwable $exception) {
Log::error($exception);
}
}
Expand Down

0 comments on commit d51fc63

Please sign in to comment.