PHP code example of phambinh / lara-exception-notifier

1. Go to this page and download the library: Download phambinh/lara-exception-notifier library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phambinh / lara-exception-notifier example snippets




return [
    'exception_notifier' => [
        // allow true or false
        // true is enable notify when have exception
        // false is disable notify
        'enable' => true,

        // The channel you want to nofity
        // Now, support only slack :D
        'channel' => ['slack'],

        // Your slack web hook
        // more information about slack web hook: https://api.slack.com/incoming-webhooks
        'slack_web_hook_url' => ''
    ]
];

    // use Phambinh\LaraExceptionNotifier\Events\HasExceptionEvent;

    public function report(Exception $exception)
    {
        parent::report($exception);

        if ($this->shouldReport($exception)) {
            event(new HasExceptionEvent($exception));
        }
    }



use Phambinh\LaraExceptionNotifier\Events\HasExceptionEvent;

class MyController extends Controller
{
    public function index()
    {
        try {
            // your code here
        } catch (\Exception $e) {
            event(new HasExceptionEvent($e));
        }
    }
}



use Phambinh\LaraExceptionNotifier\Events\HasExceptionEvent;
use Phambinh\LaraExceptionNotifier\Exceptions\QuietException;

class MyController extends Controller
{
    public function index()
    {
        $a = 1;
        $b = 0;

        try {
            $c = $a/$b;
        } catch (\Exception $e) {
            event(new HasExceptionEvent($e, [
                'a' => $a,
                'b' => $b,
            ]));

            throw new QuietException($e);
            // noti
            // throw $e; # Don't use, because you will be received duplicate message
            // no throw # The laravel will never log
        }
    }
}