1. Go to this page and download the library: Download mountain/laraslack 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/ */
mountain / laraslack example snippets
use ThomasMountain\LaraSlack\Facades\LaraSlack;
// Simplest possible message.
LaraSlack::send('Deploy finished');
// Same thing, with the builder.
LaraSlack::message('Deploy finished')->send();
use ThomasMountain\LaraSlack\LaraSlackManager;
app(LaraSlackManager::class)->send('Deploy finished');
use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
use ThomasMountain\LaraSlack\Facades\LaraSlack;
protected function setUp(): void
{
parent::setUp();
config()->set('slack.endpoint', 'https://hooks.slack.test/services/T000/B000/XXXX');
Http::fake(['*' => Http::response('ok')]);
}
public function test_it_alerts_ops_when_a_deploy_finishes(): void
{
LaraSlack::message('Deploy finished')->send();
Http::assertSent(function (Request $request) {
$payload = json_decode($request->data()['payload'], true, flags: JSON_THROW_ON_ERROR);
$this->assertSame('Deploy finished', $payload['text']);
return true;
});
}
use ThomasMountain\LaraSlack\Exceptions\SlackRequestException;
try {
LaraSlack::message('Deploy finished')->send();
} catch (SlackRequestException $e) {
$e->status; // HTTP status, or null if Slack was never reached
$e->body; // Slack's response body, e.g. 'invalid_payload'
$e->payload; // what was sent
}