Download the PHP package tdx/notify-laravel without Composer
On this page you can find all versions of the php package tdx/notify-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package notify-laravel
Notify-Laravel
A simple PHP package for sending notifications from laravel via Slack with incoming webhooks or via email. This package will automatically format an instance of exception object, string text, or an array for a message. While sending an exception as a message, it will attach an information of "user agent", "request uri", and "ip address. For Laravel, using this class in a Exceptions\Handler.php class is prefered.
Requirements
- PHP >=7.0
- laravel/framework >=5.3
- laravel/slack-notification-channel: "^2.3.1"
Installation
1. Use composer to install this package.
2. Add 'provider' and 'alias' for config\app.php. (No need above Laravel 5.5. Thanks to Auto-Discovery feature! YaY)
3. Publish necessary config and view files.
add --force
option to overwrite previously published files.
These commands should create
If these publish commands does not work, try
It will clear the config cache.
4. Create an incoming webhook on your Slack account. You need to write Webhook URL in config\slack.php file to send a message via Slack.
Settings
Write values for some config files.
In config\slack.php,
In .env, set suitable values for mail,
and add
If the value = true, the adapter is turned on (The adapter can send a message). If the value = false, the adapter is turned off (The adapter cannot send a message). If there is no value defined in .env file, false is used as default. Mention will be attached at the beginning of the content.
How to send Messages
This class automatically formats and sends an message. The content can be an exception object, string, or an array.
-
Sending messages from Facade.
- Sending messages from Instance.
Options for Adapters
For SlackAdapter,
Parameter | Type | Description |
---|---|---|
to |
string | channel or username that messages is going to be sent to. |
from |
string | username for the message. |
icon |
string | The icon URL or stamp string. (e.g.) :smile: |
fields |
array | has UserAgent and RequestUri if there exist. |
max_retry |
bool | maximum number of retries. (default max_retry = 3 ) |
force |
bool | forces to send if it is true. Otherwise, do not force (follows to config/active values). |
mention |
string | mention is attached at the beginning of the content. (e.g.) '@channel' |
raw |
bool | send text without formatting if it is true. |
For MailAdapter,
Parameter | Type | Description |
---|---|---|
to |
string | email address that messages is going to be sent to. |
from |
string | username for the email. This does not need to be actual email address. |
subject |
string | subject for the email. |
fields |
array | has UserAgent and RequestUri if there exist. |
max_retry |
bool | maximum number of retries. (default max_retry = 3 ) |
force |
bool | force to send if it is true. Otherwise, do not force (follow to active values). |
Example of Implementation using Laravel Exception Handler
In App\Exceptions\Handler class,
How to Create Other Adapter
- Create a class which implements AdapterInterface in an Adapters folder.
- Name the class to xxxAdapter. xxx will be an adapter name that is going to be called.
- Modify config/config.php file to define default values for the adapter.
Notes
If an adapter failed to send a message, it will automatically retry to send it. Write ['max_retry' = SOME_NUMBER] in the options array to change the number of attempts (default max_retry = 3). If all attempts failed, it will throw NotifyException. To get more specific info about the error, you should check laravel.log file (The log file captures errors for all attempts).
All versions of notify-laravel with dependencies
laravel/framework Version >=5.3
laravel/slack-notification-channel Version ^2.3.1