All Projects → gpressutto5 → Laravel Slack

gpressutto5 / Laravel Slack

Licence: mit
#️⃣ Slack notification for Laravel as it should be. Easy, fast, simple and highly testable.

Projects that are alternatives of or similar to Laravel Slack

Server Monitor App
A PHP application to monitor the health of your servers
Stars: ✭ 141 (-46.39%)
Mutual labels:  laravel, slack
Laralack
A Slack clone written in PHP & Laravel framework
Stars: ✭ 82 (-68.82%)
Mutual labels:  laravel, slack
Laravel Failed Job Monitor
Get notified when a queued job fails
Stars: ✭ 582 (+121.29%)
Mutual labels:  laravel, slack
Laravel Slack Slash Command
Make a Laravel app respond to a slash command from Slack
Stars: ✭ 215 (-18.25%)
Mutual labels:  laravel, slack
Laravel Nestedset
Effective tree structures in Laravel 4-5
Stars: ✭ 3,045 (+1057.79%)
Mutual labels:  laravel
Laravel Nova Excel
🚀 Supercharged Excel exports for Laravel Nova Resources
Stars: ✭ 259 (-1.52%)
Mutual labels:  laravel
Old Lms Laravel
Laravel Learning Management System (LMS)
Stars: ✭ 258 (-1.9%)
Mutual labels:  laravel
Laravel Email Campaigns
Send email campaigns using Laravel
Stars: ✭ 257 (-2.28%)
Mutual labels:  laravel
Seo Helper
🔍 SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization).
Stars: ✭ 262 (-0.38%)
Mutual labels:  laravel
Otter
A relatively automatic CRUD backend administration panel for Laravel
Stars: ✭ 261 (-0.76%)
Mutual labels:  laravel
Laraform
Reactive Form Builder for Vue.js with Laravel Support
Stars: ✭ 259 (-1.52%)
Mutual labels:  laravel
Yascmf
已过时,请访问5.2新版仓库
Stars: ✭ 258 (-1.9%)
Mutual labels:  laravel
Lando
A development tool for all your projects that is fast, easy, powerful and liberating
Stars: ✭ 3,142 (+1094.68%)
Mutual labels:  laravel
S Cart
This project has been replaced by https://github.com/s-cart/s-cart
Stars: ✭ 258 (-1.9%)
Mutual labels:  laravel
Laravel Money
Currency formatting and conversion package for Laravel
Stars: ✭ 261 (-0.76%)
Mutual labels:  laravel
Query track
Find time-consuming database queries for ActiveRecord-based Rails Apps
Stars: ✭ 258 (-1.9%)
Mutual labels:  slack
Laravel Robots Middleware
Enable or disable the indexing of your app
Stars: ✭ 259 (-1.52%)
Mutual labels:  laravel
Nova Backup Tool
A Laravel Nova tool to backup your app
Stars: ✭ 260 (-1.14%)
Mutual labels:  laravel
Laravel Demo Mode
A package to protect your work in progress from prying eyes
Stars: ✭ 259 (-1.52%)
Mutual labels:  laravel
Quicksand
Easily schedule regular cleanup of old soft-deleted Eloquent data.
Stars: ✭ 259 (-1.52%)
Mutual labels:  laravel

Build Status codecov Latest Stable Version PHP from Packagist Laravel Version Total Downloads License
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:

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... ❤️');
//         ↑  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 column slack_channel and store the @username or the #channel name there. If you already store it but on a different column you can create a method getSlackChannelAttribute.

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!');

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].