, (*1)
Laravel Slack Package
A laravel package for sending Slack messages, (*2)
For more information see Slack, (*3)
Requirements
Laravel 5.1 or later, (*4)
Installation
Installation is a quick 3 step process:, (*5)
- Download laravel-slack using composer
- Configure your HTTP Adapter
- Enable the package in app.php
- Configure your Slack credentials
- (Optional) Configure the package facade
Step 1: Download laravel-slack using composer
Add nimbles-nl/laravel-slack by running the command:, (*6)
composer require nimbles-nl/laravel-slack
Configure the http adapter in your AppServiceProvider.php, (*7)
``` php
use GuzzleHttp\Client as GuzzleClient;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;, (*8)
$this->app->singleton('http.client', function() {
return new GuzzleAdapter(new GuzzleClient());
});, (*9)
### Step 3: Enable the package in app.php
Register the Service in: **config/app.php**
``` php
Nimbles\Slack\SlackServiceProvider::class,
````
### Step 4: Configure Slack credentials
php artisan vendor:publish, (*10)
Add this in you **.env** file
SLACK_ACCESS_TOKEN=your_secret_slack_access_token
```, (*11)
Register the Slack Facade in: config/app.php, (*12)
``` php
'aliases' => [, (*13)
'App' => Illuminate\Support\Facades\App::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
'Auth' => Illuminate\Support\Facades\Auth::class,
...
'Slack' => Nimbles\Slack\Facade\Slack::class,
Usage
-----
``` php
$slackMessage = new SlackMessage('You re looking great today!', '#general', 'AwesomeBot', 'https://www.link-to-avatar.com/image.png');
app('slack')->sendMessage($slackMessage);
Or if you want to use facade, add this in your class after namespace declaration:, (*14)
``` php
Slack::sendMessage(new SlackMessage('You are looking great today!'));
````, (*15)