PHP code example of jmrashed / laravel-slack-notifier

1. Go to this page and download the library: Download jmrashed/laravel-slack-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/ */

    

jmrashed / laravel-slack-notifier example snippets


use Jmrashed\SlackNotifier\Facades\SlackNotifier;

SlackNotifier::send('Test message');

SlackNotifier::send(new \RuntimeException('Test exception'));

return Application::configure(basePath: dirname(__DIR__))
    ->withExceptions(function (Exceptions $exceptions) {
        $exceptions->reportable(function (Throwable $e) {
            \Jmrashed\SlackNotifier\Facades\SlackNotifier::send($e);
        });
    })->create();

public function register(): void
{
    $this->reportable(function (Throwable $e) {
        \Jmrashed\SlackNotifier\Facades\SlackNotifier::send($e);
    });
}

public function report(Throwable $exception)
{
    if ($this->shouldReport($exception)) {
        \Jmrashed\SlackNotifier\Facades\SlackNotifier::send($exception);
    }

    parent::report($exception);
}

public function report(Exception $exception)
{
    if ($this->shouldReport($exception)) {
        \Jmrashed\SlackNotifier\Facades\SlackNotifier::send($exception);
    }

    parent::report($exception);
}

use Jmrashed\SlackNotifier\Facades\SlackNotifier;

$variable = 'message';  // or $variable = ['key' => 'value'];
SlackNotifier::send($variable);

// config/slack-notifier.php

'webhook_urls' => [
    'default' => 'https://hooks.slack.com/services/ABC',
    'testing' => 'https://hooks.slack.com/services/DEF',
],

use Jmrashed\SlackNotifier\Facades\SlackNotifier;

SlackNotifier::to('testing')->send('Test message');

use Jmrashed\SlackNotifier\Facades\SlackNotifier;

SlackNotifier::channel('reminders')->send('Test message');

use Jmrashed\SlackNotifier\Facades\SlackNotifier;

SlackNotifier::username('My Laravel Bot')->emoji(':tada:')->send('Test message');

// config/slack-notifier.php

'formatter' => App\Formatters\CustomSlackNotifierFormatter::class,

use Jmrashed\SlackNotifier\Facades\SlackNotifier;

SlackNotifier::cacheSeconds(60)->send(new \RuntimeException('Test exception'));
dotenv
APP_NAME=Laravel
LOG_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/ABC
LOG_SLACK_CHANNEL=
LOG_SLACK_EMOJI=:boom:
LOG_SLACK_CACHE_SECONDS=0
bash
php artisan vendor:publish --tag="slack-notifier"