Download the PHP package jocoonopa/laravel-slack without Composer
On this page you can find all versions of the php package jocoonopa/laravel-slack. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-slack
Based on illuminate/mail
About Laravel Slack
Slack notification for Laravel as it should be. Easy, fast, simple and highly testable. Since it uses On-Demand Notifications, it requires Laravel 5.5 or higher.
Installation
Require this package in your composer.json and update your dependencies:
Since this package supports Laravel's Package Auto-Discovery you don't need to manually register the ServiceProvider.
After that, publish the configuration file:
You're gonna need to configure an "Incoming Webhook" integration for your Slack team.
Configuration
On the published configuration file config/laravel-slack.php
you can change options like the Webhook URL, the default channel,
the application name and the application image.
For security reasons you shouldn't commit your Webhook URL,
so this package will, by default, use the environment variable
SLACK_WEBHOOK_URL
. You can just add it to your .env
file.
Like this:
Usage
You can send simple Slack messages like this:
-
Send message to a channel:
-
Send message to an user:
-
Send message to multiple users:
-
Mix it up:
-
No recipient:
-
Send SlackMessage objects:
-
Send to user:
You can use any object as a recipient as long as they have the property
slack_channel
. If you are using Models you can just create the columnslack_channel
and store the@username
or the#channel
name there. If you already store it but on a different column you can create a methodgetSlackChannelAttribute
. - Send message by specifying webhook:
Testing
When testing you can easily mock the Slack service by calling
Slack::fake()
it will return a SlackFake
object that won't
send any message for real and will save them to an array.
You can get this array by calling Slack::sentMessages()
.
This class also has some helper methods for you to use when testing:
-
Assert that at least one message with the content 'fake' was sent:
-
Assert that at least two messages with the content being a string longer than 5 characters were sent:
-
Assert that exactly five messages where the content content contains the word 'test' were sent:
- Assert that exactly three messages were sent:
Since this package uses illuminate/notifications
to send notifications
you can mock the Notification service instead of the Slack one
and use the class NotificationFake
in your tests.
Take a look.
All versions of laravel-slack with dependencies
guzzlehttp/guzzle Version ^6.3 || ^7.0
illuminate/notifications Version ^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0
illuminate/support Version ^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0
laravel/slack-notification-channel Version ^3.1