Skip to content

Commit

Permalink
Merge pull request #13 from DevDavido/laravel-10
Browse files Browse the repository at this point in the history
feat: Provide Laravel 10 support
  • Loading branch information
jeremykenedy authored Jan 21, 2024
2 parents 02217d7 + cf0df06 commit b56d851
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 171 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

language: php
sudo: required
dist: trusty
group: edge

php:
- 7.2.5
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2

sudo: false

Expand All @@ -16,7 +16,7 @@ services:

before_script:
- mysql -u root -e 'create database laravelexceptionnotifier;'
- curl -s http://getcomposer.org/installer | php
- curl -s https://getcomposer.org/installer | php
- php composer.phar install
- composer create-project --prefer-dist laravel/laravel laravelexceptionnotifier
- cp .env.travis laravelexceptionnotifier/.env
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"php": "^8.0"
},
"require-dev": {
"laravel/framework": "9.*"
"laravel/framework": "9.*|10.*"
},
"autoload": {
"psr-4": {
Expand Down
96 changes: 48 additions & 48 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Laravel Exception Notifier | A Laravel 5, 6, 7, 8, and 9 Exceptions Email Notification [Package](https://packagist.org/packages/jeremykenedy/laravel-exception-notifier)
# Laravel Exception Notifier | A Laravel 5, 6, 7, 8, 9 and 10 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 @@ -18,17 +18,20 @@ 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, 5.8, 6, 7, 8, and 9+.
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, 9, and 10.

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

## Requirements
* [Laravel 5.2+, 6, 7, 8, or 9+](https://laravel.com/docs/installation)
* [Laravel 5.2+, 6, 7, 8, 9, or 10](https://laravel.com/docs/installation)

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

Laravel 9+ use:
Laravel 9-10 use:

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

#### NOTE: If upgrading to Laravel 9 from an older version of this package you will need to republish the assets with:
#### NOTE: If upgrading to Laravel 9 or 10 from an older version of this package you will need to republish the assets with:

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

```php
use App\Mail\ExceptionOccured;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use App\Mail\ExceptionOccurred;
use Illuminate\Support\Facades\Log;
use Mail;
use Illuminate\Support\Facades\Mail;
use Throwable;
```

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

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

##### Add the `sendEmail()` method:
```php
/**
* Sends an email upon exception.
*/
public function sendEmail(Throwable $exception): void
{
try {
$content = [
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTrace(),
'url' => request()->url(),
'body' => request()->all(),
'ip' => request()->ip(),
];
Mail::send(new ExceptionOccurred($content));
} catch (Throwable $exception) {
Log::error($exception);
}
}
```

##### Add or update the `register()` method:
```php
/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
public function register(): void
{
$this->reportable(function (Throwable $e) {
$this->sendEmail($e);
$enableEmailExceptions = config('exceptions.emailExceptionEnabled');
if ($enableEmailExceptions) {
$this->sendEmail($e);
}
});
}
```
#### Laravel 8 and Below:
##### In `App\Exceptions\Handler.php` replace the `report()` method with:
##### Replace the `report()` method with:
```php
/**
Expand Down Expand Up @@ -139,37 +169,7 @@ Register the package with laravel in `config/app.php` under `providers` with the
}
```
6. In `App\Exceptions\Handler.php` add the method `sendEmail()`:
#### Laravel 9 and Above:
```php
/**
* Sends an email upon exception.
*
* @param \Throwable $exception
*
* @return void
*/
public function sendEmail(Throwable $exception)
{
try {
$content['message'] = $exception->getMessage();
$content['file'] = $exception->getFile();
$content['line'] = $exception->getLine();
$content['trace'] = $exception->getTrace();
$content['url'] = request()->url();
$content['body'] = request()->all();
$content['ip'] = request()->ip();
Mail::send(new ExceptionOccured($content));
} catch (Throwable $exception) {
Log::error($exception);
}
}
```
#### Laravel 8 and Below:
##### Add the method `sendEmail()`:
```php
/**
* Sends an email upon exception.
Expand All @@ -192,9 +192,9 @@ Register the package with laravel in `config/app.php` under `providers` with the
}
```
7. Configure your email settings in the `.env` file.
6. Configure your email settings in the `.env` file.
8. Add the following (optional) settings to your `.env` file and enter your settings:
7. Add the following (optional) settings to your `.env` file and enter your settings:
* **Note:** the defaults for these are located in `config/exception.php`
Expand All @@ -221,7 +221,7 @@ Register the package with laravel in `config/app.php` under `providers` with the
├── .env.example
├── App
│   ├── Mail
│   │   └── ExceptionOccured.php
│   │   └── ExceptionOccurred.php
│   └── Traits
│   └── ExceptionNotificationHandlerTrait.php
├── LaravelExceptionNotifier.php
Expand Down
66 changes: 0 additions & 66 deletions src/App/Mail/ExceptionOccured.php

This file was deleted.

65 changes: 65 additions & 0 deletions src/App/Mail/ExceptionOccurred.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class ExceptionOccurred extends Mailable
{
use Queueable, SerializesModels;

private array $content;

/**
* Create a new message instance.
*/
public function __construct($content)
{
$this->content = $content;
}

/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
$emailsTo = config('exceptions.emailExceptionsTo', false) ?
str_getcsv(config('exceptions.emailExceptionsTo')) :
null;
$emailsCc = config('exceptions.emailExceptionCCto', false) ?
str_getcsv(config('exceptions.emailExceptionCCto')) :
null;
$emailsBcc = config('exceptions.emailExceptionBCCto', false) ?
str_getcsv(config('exceptions.emailExceptionBCCto')) :
null;
$fromSender = config('exceptions.emailExceptionFrom');
$subject = config('exceptions.emailExceptionSubject');

return new Envelope(
from: $fromSender,
to: $emailsTo,
cc: $emailsCc,
bcc: $emailsBcc,
subject: $subject
);
}

/**
* Get the message content definition.
*/
public function content(): Content
{
$view = config('exceptions.emailExceptionView');

return new Content(
view: $view,
with: [
'content' => $this->content,
]
);
}
}
Loading

0 comments on commit b56d851

Please sign in to comment.