PHP code example of stasadev / laravel-slack-notifier
1. Go to this page and download the library: Download stasadev/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/ */
stasadev / laravel-slack-notifier example snippets
use Stasadev\SlackNotifier\Facades\SlackNotifier;
SlackNotifier::send(new \RuntimeException('Test exception'));
SlackNotifier::send('Test message');
// In Laravel 11.x and later
// bootstrap/app.php
return Application::configure(basePath: dirname(__DIR__))
->withExceptions(function (Exceptions $exceptions) {
$exceptions->reportable(function (Throwable $e) {
\Stasadev\SlackNotifier\Facades\SlackNotifier::send($e);
});
})->create();
// In Laravel 8.x, 9.x, 10.x
// app/Exceptions/Handler.php
public function register(): void
{
$this->reportable(function (Throwable $e) {
\Stasadev\SlackNotifier\Facades\SlackNotifier::send($e);
});
}
// In Laravel 7.x
// app/Exceptions/Handler.php
public function report(Throwable $exception)
{
if ($this->shouldReport($exception)) {
\Stasadev\SlackNotifier\Facades\SlackNotifier::send($exception);
}
parent::report($exception);
}
// In Laravel 5.7.x, 5.8.x, 6.x
// app/Exceptions/Handler.php
public function report(Exception $exception)
{
if ($this->shouldReport($exception)) {
\Stasadev\SlackNotifier\Facades\SlackNotifier::send($exception);
}
parent::report($exception);
}
use Stasadev\SlackNotifier\Facades\SlackNotifier;
$variable = 'message';
// $variable = ['test' => 'array'];
// $variable = new stdClass();
SlackNotifier::send($variable);