Download the PHP package jmrashed/laravel-slack-notifier without Composer
On this page you can find all versions of the php package jmrashed/laravel-slack-notifier. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jmrashed/laravel-slack-notifier
More information about jmrashed/laravel-slack-notifier
Files in jmrashed/laravel-slack-notifier
Package laravel-slack-notifier
Short Description A package for sending exceptions and variables to Slack notifications
License MIT
Homepage https://github.com/jmrashed/laravel-slack-notifier
Informations about the package laravel-slack-notifier
Laravel Slack Notifier Package
A simple package to send notifications to Slack using webhooks, with support for customizations such as multiple webhooks, channels, bot name, emojis, and more.
Table of Contents
- Installation
- Configuration
- Usage
- Send Message
- Report Exceptions
- Dump Variables
- Multiple Webhooks
- Send Message to Another Channel
- Customize Slack Bot
- Message Formatting
- Additional Context
- Exception Stack Trace Filtering
- Cache Same Exceptions
- Testing
- License
Installation
To install the package, run the following composer command:
Configuration
Once the package is installed, you need to set up the environment variables for the Slack webhook and other configuration options.
Add the following entries to your .env
file:
LOG_SLACK_WEBHOOK_URL
is required and should be set to your Slack webhook URL. Learn how to create a webhook.- The other environment variables are optional. You can set
LOG_SLACK_CHANNEL
to specify a channel or useLOG_SLACK_EMOJI
to set a custom emoji for the Slack messages.
To temporarily disable notifications, either comment out or set the LOG_SLACK_WEBHOOK_URL
to an empty string or null
.
Optionally, you can publish the config file with the following Artisan command:
Usage
Send Message
To send a message to Slack, use the following code:
You can also send exceptions:
Report Exceptions
To automatically report exceptions to Slack, configure your Laravel exception handler.
Laravel 11.x and later
In bootstrap/app.php
:
Laravel 8.x, 9.x, and 10.x
In app/Exceptions/Handler.php
:
Laravel 7.x
In app/Exceptions/Handler.php
:
Laravel 5.x, 6.x
In app/Exceptions/Handler.php
:
Dump Variables
You can also send variables (strings, arrays, objects) to Slack:
Multiple Webhooks
You can configure multiple webhook URLs in the config/slack-notifier.php
file:
To use a specific webhook, specify the webhook name:
Send Message to Another Channel
To send a message to a different Slack channel, use the channel
method:
Customize Slack Bot
You can customize the bot’s name and emoji:
Message Formatting
If you need to format the message before sending, extend the default SlackNotifierFormatter
class:
Additional Context
You can include additional context in the message. Use the context
method to pass additional information as an attachment in the message.
Exception Stack Trace Filtering
Filter out unnecessary stack trace lines (e.g., from framework files) by configuring the dont_trace
option in the config.
Cache Same Exceptions
To avoid logging the same exception multiple times, use the LOG_SLACK_CACHE_SECONDS
configuration. It defines how long exceptions will be cached before being logged again.
Alternatively, you can specify the cache duration programmatically:
Testing
To run the tests for this package, use the following command:
License
This package is licensed under the MIT License. See the License File for more details.
All versions of laravel-slack-notifier with dependencies
ext-json Version *
laravel/slack-notification-channel Version ^1.0 || ^2.0 || ^3.0
monolog/monolog Version ^1.12 || ^2.0 || ^3.0
symfony/polyfill-php80 Version ^1.20