Laravel integration for the Slack, including facades and service providers.
MIT License
Laravel integration for the Slack, including facades and service providers. This package allows you to use Slack for PHP easily and elegantly in your Laravel app.
composer require jeremykenedy/slack-laravel
Uses package auto discovery feature, no need to edit the config/app.php
file.
Register the package with laravel in config/app.php
under providers
with the following:
'providers' => [
jeremykenedy\Slack\Laravel\ServiceProvider::class,
];
Register the package with laravel in config/app.php
under aliases
with the following:
'aliases' => [
'Slack' => jeremykenedy\Slack\Laravel\Facade::class,
];
Publish the config file from your projects root folder in terminal by running:
php artisan vendor:publish --tag=slacklaravel
Create an incoming webhook for each Slack team you'd like to send messages to. You'll need the webhook URL(s) in order to configure this package.
.env
(All)Configure Slack for Laravel in your .env
file by adding and editing the following:
DEFAULT_SLACK_WEBHOOK_ENDPOINT=https://hooks.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXX
DEFAULT_SLACK_CHANNEL='#general'
DEFAULT_SLACK_USERNAME=Robot
DEFAULT_SLACK_ICON=':ghost:'
DEFAULT_SLACK_LINKNAMES_CONVERTED=FALSE
DEFAULT_SLACK_UNFURL_LINKS_STATUS=FALSE
DEFAULT_SLACK_UNFURL_MEDIA_STATUS=TRUE
DEFAULT_SLACK_ALLOW_MARKDOWN=TRUE
DEFAULT_SLACK_MARKDOWN_FIELDS="'text','title'"
The config file comes with defaults and placeholders. Configure at least one team and any defaults you'd like to change.
Default configurations are published into config/slack.php
and the values can be set in the .env
file like so:
DEFAULT_SLACK_WEBHOOK_ENDPOINT=https://hooks.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXX
DEFAULT_SLACK_CHANNEL='#general'
DEFAULT_SLACK_USERNAME=Robot
DEFAULT_SLACK_ICON=':ghost:'
DEFAULT_SLACK_LINKNAMES_CONVERTED=FALSE
DEFAULT_SLACK_UNFURL_LINKS_STATUS=FALSE
DEFAULT_SLACK_UNFURL_MEDIA_STATUS=TRUE
DEFAULT_SLACK_ALLOW_MARKDOWN=TRUE
DEFAULT_SLACK_MARKDOWN_FIELDS="'text','title'"
\Slack::send('Hey');
Slack::send('Hi Slack, from the API :)');
Slack::to('#testing')->send('Hi Testing!');
Slack::to('@jeremykenedy')->send('Hi Jeremy!');
Use the fake
method on the Facade
Slack::fake()
This provides the following
Slack::assertMessageSent(function($messages) {
// search in all messages
});
Slack::assertMessageSentTo($channel, function($messages) {
// search in all messages posted to $channel
});
Slack for Laravel is licensed under the MIT license for both personal and commercial products. Enjoy!