gpressutto5/laravel-slack
最新稳定版本:2.4.0
Composer 安装命令:
composer require gpressutto5/laravel-slack
包简介
Slack notification for Laravel as it should be.
README 文档
README
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.
This library is archived and no longer maintained. It works as expected, but I don't have time to maintain it anymore. As a last update, I've removed version constraints from the
composer.jsonfile, so you can use it with any future Laravel versions. Feel free to fork it and use it as you wish.
Installation
Require this package in your composer.json and update your dependencies:
composer require gpressutto5/laravel-slack
Since this package supports Laravel's Package Auto-Discovery you don't need to manually register the ServiceProvider.
After that, publish the configuration file:
php artisan vendor:publish --provider="Pressutto\LaravelSlack\ServiceProvider"
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:
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX
Usage
You can send simple Slack messages like this:
- Send message to a channel:
\Slack::to('#finance')->send('Hey, finance channel! A new order was created just now!');
- Send message to an user:
\Slack::to('@joe')->send("Hey Joe! It looks like you've forgotten your password! Use this token to recover it: as34bhdfh");
- Send message to multiple users:
\Slack::to(['@zoe', '@amy', '@mia'])->send('I swear, honey, you are the only one... :heart:'); // ↑ look at this array ↑
- Mix it up:
\Slack::to('#universe', '@god', '#scientists')->send(':thinking_face:'); // ↑ what? I don't need that array? ↑
- No recipient:
\Slack::send('Default message to the default channel, set on config/laravel-slack.php.');
- Send SlackMessage objects:
class HelloMessage extends SlackMessage { public $content = "Hey bob, I'm a sending a custom SlackMessage"; public $channel = '@bob'; } \Slack::send(new SlackMessage());
-
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_channeland store the@usernameor the#channelname there. If you already store it but on a different column you can create a methodgetSlackChannelAttribute.
class User extends Model { public function getSlackChannelAttribute(): string { return $this->attributes['my_custom_slack_channel_column']; } } \Slack::to(User::where('verified', true))->send('Sending message to all verified users!');
- Send message by specifying webhook:
\Slack::to('#finance')->webhook('https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX')->send('Hey, finance channel! A new order was created just now!');
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:
Slack::assertSent(function (SlackMessage $message) { return $message->content === 'fake'; });
- Assert that at least two messages with the content being a string longer than 5 characters were sent:
Slack::assertSent(function (SlackMessage $message) { return strlen($message->content) >= 100; }, 2);
- Assert that exactly five messages where the content content contains the word 'test' were sent:
Slack::assertSent(function (SlackMessage $message) { return strpos($message->content, 'test') !== false; }, 5, true);
- Assert that exactly three messages were sent:
Slack::assertSentCount(3);
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.
gpressutto5/laravel-slack 适用场景与选型建议
gpressutto5/laravel-slack 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 543.97k 次下载、GitHub Stars 达 289, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「slack」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gpressutto5/laravel-slack 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gpressutto5/laravel-slack 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gpressutto5/laravel-slack 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Highly Opinionated Symfony3/4 Deployer Recipe
This bundle provides integration with the Slack API library, allowing you to interact with the Slack API from within your Symfony projects
Wrapper for Slack Web API
Alfabank REST API integration
This is my package support-tickets-notifications
Console commands
统计信息
- 总下载量: 543.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 290
- 点击次数: 20
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04