Download the PHP package michaelthuren/slack-laravel-client without Composer
On this page you can find all versions of the php package michaelthuren/slack-laravel-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download michaelthuren/slack-laravel-client
More information about michaelthuren/slack-laravel-client
Files in michaelthuren/slack-laravel-client
Package slack-laravel-client
Short Description Slack notification for Laravel as it should be.
License MIT
Informations about the package slack-laravel-client
Based on illuminate/mail
Slack Laravel Client
Supported Laravel versions 5.5 - 9+
Based on gpressutto5/laravel-slack
Slack notification for Laravel as it should be. 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
.
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:
- More test helper methods are coming...
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 slack-laravel-client with dependencies
guzzlehttp/guzzle Version ^7.4
illuminate/notifications Version ^9.0
illuminate/support Version ^9.0
laravel/slack-notification-channel Version ^2.4