Service that helps you to send notifications for a series of failed exceptions.

Overview

Laravel Failure Notifier

This package helps you to track your exceptions and do what you want to do with them such as sending an SMS or and Email.

You can specify the amount of time to count the exceptions.

If you had more exceptions than you expect, the service will run your function, then you can send a notification or whatever you want.

This package uses your default cache driver to count the exceptions. You are free to choose the driver, but we suggest you to use Redis for that.

Installation

You need to add this package to your project by:

composer require kam2yar/failure-notifier

Optional: The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file:

'providers' => [
    // ...
    FailureNotifier\FailureNotifierServiceProvider::class
]

After you need to run the below command to copy the configuration file to your project directory.

php artisan vendor:publish --provider="FailureNotifier\FailureNotifierServiceProvider"

After this, you are free to remove it from your provider's array.

Add the service to the handler

You must add the service to the Exceptions\Handler.php file to capture the exceptions.

Add the report method to the "Handler" class as below:

public function report(Throwable $exception)
{
    if ($this->shouldReport($exception) and app()->bound(FailureNotifier::class) and app()->bound(FailureHandlerInterface::class)) {
        app(FailureNotifier::class)->capture($exception);
    }

    parent::report($exception);
}

Write your custom failure handler

You must write a new class in your project and pass it to the capture method that implements the FailureHandlerInterface interface:

use FailureNotifier\FailureHandlerInterface;.
use Illuminate\Support\Facades\Log;
use Throwable;

class FailureHandler implements FailureHandlerInterface
{
    public function handleException(Throwable $exception, int $failureCount)
    {
        $exceptionClass = get_class($exception);

        switch ($exceptionClass) {
            default:
                Log::warning('Handle default exception', ['class' => $exceptionClass]);
                break;
        }
    }
}

Bind your custom handler to your application

Now you need to add your custom failure handler to your App\Providers\AppServiceProvider file.

Add the bellow code to the boot function:

public function boot()
{
    $this->app->singleton(FailureHandlerInterface::class, function ($app) {
        // Your custom failure handler
        
        return new FailureHandler();       
    });
}

Configuration

You can change the service configuration by editing the config\failure-notifier.php file.

You can have a setting for each type of exception. or you can leave it to use the default configuration.

To add a new exception you need to add a new record to the "exceptions" array like the below example:

   \App\Exceptions\ExampleException::class => [
       'count' => 5,
       'interval' => 600,
       'lock_until' => 600,
       'active' => true
   ],

Parameters

Count: Minimum count of exceptions needs to raise to run your function.

Interval: Seconds to store the count of exceptions in the cache.

Lock Until: Seconds to prevent sending duplicate notify

Active: Enable or disable service for this type of exception

Deactivate the service

If you need to disable the service, you can set a new key in your .env file.

FAILURE_NOTIFIER_ACTIVE=false

Contribution

Please tell me about the feature or issues before start developing it. Thank you.

You might also like...
Laravel SMS allows you to send SMS from your Laravel application using multiple sms providers, allow to add custom sms provider

Laravel SMS Laravel SMS allows you to send SMS from your Laravel application using multiple sms providers, allow to add custom sms provider Requiremen

Standalone PHP library for easy devices notifications push.

NotificationPusher Standalone PHP library for easy devices message notifications push. Feel free to contribute! Thanks. Contributors Cédric Dugat (Aut

A very lightweight library to handle notifications the smart way.
A very lightweight library to handle notifications the smart way.

NAMSHI | Notificator Notificator is a very simple and lightweight library to handle notifications the smart way. It took inspiration from other librar

Takes care of Apple push notifications (APNS) in your PHP projects.

Notificato Notificato takes care of push notifications in your PHP projects. Italian: notificato è: participio passato English: notified Why use Notif

Sends notifications via one or more channels (email, SMS, ...).

Notifier Component The Notifier component sends notifications via one or more channels (email, SMS, ...). Resources Documentation Contributing Report

Laravel Security Notifications

This package adds security notifications to warn your users when significant security events occur so that they aren't the next victim of an attacker.

Laravel package to launch toast notifications.
Laravel package to launch toast notifications.

Laravel package to launch toast notifications. This package provides assistance when using toast notifications. Using the iziTOAST package, which allo

Laravel Subscribable Notifications

Laravel Subscribable Notifications This package allows you to subscribe your app Users to your app Notifications and dispatch them without specifying

Push notifications Library for PHP

Push notifications Library for PHP Supported Protocols Protocol Supported Driver Options APNs (Token Based) ✓ APNs\Token APNs\Token\Option APNs (Certi

Releases(1.8)
Owner
Kamyar Gerami
Backend developer
Kamyar Gerami
Larafirebase is a package thats offers you to send push notifications or custom messages via Firebase in Laravel.

Introduction Larafirebase is a package thats offers you to send push notifications or custom messages via Firebase in Laravel. Firebase Cloud Messagin

Kutia Software Company 264 Jan 7, 2023
:computer: Send notifications to your desktop directly from your PHP script

About JoliNotif JoliNotif is a cross-platform PHP library to display desktop notifications. It works on Linux, Windows or MacOS. Requires PHP >= 7.2 (

JoliCode 1.2k Dec 29, 2022
A PHP Library to easily send push notifications with the Pushwoosh REST Web Services.

php-pushwoosh A PHP Library to easily send push notifications with the Pushwoosh REST Web Services. First sample, creating a Pushwoosh message // Crea

gomoob 63 Sep 28, 2022
Notifications in PHP (notify-send, growl, etc) like that.

#Nod Notifications in PHP (notify-send, growl, etc) like that. ##Examples Letting Nod figure out the best Adapter to use (not recommend ATM, only work

Filipe Dobreira 51 Mar 26, 2019
Send push notifications to apple devices (iPhone, iPad, iPod).

Apple Apn Push Send push notifications to apple devices (iPhone, iPad, iPod). Support authenticators: Certificate Json Web Token Supported protocols:

Vitaliy Zhuk 157 Dec 1, 2022
Send Firebase push notifications with Laravel php framework.

FCM Notification Channel for Laravel Send Firebase push notifications with Laravel php framework. Installation You can install this package via compos

Ankur Kumar 23 Oct 31, 2022
WebPush can be used to send notifications to endpoints which server delivers Web Push

WebPush can be used to send notifications to endpoints which server delivers Web Push notifications as described in the Web Push protocol. As it is standardized, you don't have to worry about what server type it relies on.

null 1.5k Jan 7, 2023
This package makes it easy to send notifications using RocketChat with Laravel 9.0+.

laravel-rocket-chat-notifications Introduction This package makes it easy to send notifications using RocketChat with Laravel 9.0+. Contents Installat

Team Nifty GmbH 25 Dec 1, 2022
This package makes it easy to send web push notifications with Laravel.

Web push notifications channel for Laravel This package makes it easy to send web push notifications with Laravel. Installation You can install the pa

Laravel Notification Channels 564 Jan 3, 2023
It's Pimcore Bundle to send notifications to Google Chat, Slack or Email from admin panel inside Pimcore

Send notifications to Discord, Google Chat, Slack and more from Pimcore It's Pimcore Bundle to send notifications to Discord, Google Chat, Slack, Tele

LemonMind.com 6 Aug 31, 2022