1. Go to this page and download the library: Download aranyasen/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/ */
aranyasen / laravel-slack example snippets
// Send a simple message to a channel, say "some-channel"
(new SlackNotification())
->channel('some-channel')
->text("Hello!")
->send();
// Send a section (Ref: https://api.slack.com/reference/block-kit/blocks#section)
(new SlackNotification())
->channel('some-channel')
->section() // Starts a section
->fields() // Starts a field in this section
->markdown(":fire: @here This is an emergency :fire:")
->endFields()
->endSection()
->send();
// Send a raw JSON block (example from https://api.slack.com/block-kit/building#block_basics)
(new SlackNotification())
->channel('some-channel')
->block([
"type" => "section",
"text" => [
"type" => "mrkdwn",
"text" => "New Paid Time Off request from <example.com|Fred Enriquez>\n\n<https://example.com|View request>",
],
])
->send();
// Compose a message and dump the JSON that'll be sent to Slack. Useful for debugging.
(new SlackNotification())
->channel('some-channel')
->text("Hello!")
->dump();
// Upload a file
(new SlackNotification())
->channel('some-channel')
->file($filePath, 'Some filename')
->upload();
// Optionally, a title, or an accompanying message can be added with a file
(new SlackNotification())
->channel('some-channel')
->file($filePath, 'Some filename')
->withInitialComment('some comment')
->withTitle('some title')
->upload();