PHP code example of gpressutto5 / laravel-slack

1. Go to this page and download the library: Download gpressutto5/laravel-slack library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gpressutto5 / laravel-slack example snippets


\Slack::to('#finance')->send('Hey, finance channel! A new order was created just now!');

\Slack::to('@joe')->send("Hey Joe! It looks like you've forgotten your password! Use this token to recover it: as34bhdfh");

\Slack::to(['@zoe', '@amy', '@mia'])->send('I swear, honey, you are the only one... :heart:');
//         ↑  look at this array  ↑

\Slack::to('#universe', '@god', '#scientists')->send(':thinking_face:');
//         ↑ what? I don't need that array? ↑

\Slack::send('Default message to the default channel, set on config/laravel-slack.php.');

class HelloMessage extends SlackMessage
{
    public $content = "Hey bob, I'm a sending a custom SlackMessage";
    public $channel = '@bob';
}
\Slack::send(new SlackMessage());

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

\Slack::to('#finance')->webhook('https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX')->send('Hey, finance channel! A new order was created just now!');

Slack::assertSent(function (SlackMessage $message) {
    return $message->content === 'fake';
});

Slack::assertSent(function (SlackMessage $message) {
    return strlen($message->content) >= 100;
}, 2);

Slack::assertSent(function (SlackMessage $message) {
    return strpos($message->content, 'test') !== false;
}, 5, true);

Slack::assertSentCount(3);
bash
php artisan vendor:publish --provider="Pressutto\LaravelSlack\ServiceProvider"