Package Data | |
---|---|
Maintainer Username: | jeremykenedy |
Maintainer Contact: | github@mak.geek.nz (maknz) |
Package Create Date: | 2017-07-21 |
Package Last Update: | 2021-01-23 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-09 03:01:59 |
Package Statistics | |
---|---|
Total Downloads: | 594,880 |
Monthly Downloads: | 8,097 |
Daily Downloads: | 275 |
Total Stars: | 54 |
Total Watchers: | 5 |
Total Forks: | 17 |
Total Open Issues: | 2 |
Laravel 5 integration for the Slack, including facades and service providers. This package allows you to use Slack for PHP easily and elegantly in your Laravel 5 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'"
use Slack;
Slack::send('Hi Slack, from the API :)');
Slack::to('#testing')->send('Hi Testing!');
Slack::to('@jeremykenedy')->send('Hi Jeremy!');
Use the fake 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!