Hooks Notifications Channel for Laravel 5.3
, (*1)
UPDATE: It seems like the Hooks service is no longer active, hence, this project has been archived., (*2)
This package makes it easy to send notifications using Hooks with Laravel 5.3., (*3)
Hooks API lets you send a notification to all users subscribed to your custom alert., (*4)
Contents
Installation
You can install the package via composer:, (*5)
``` bash
composer require lukonet/laravel-hooks-notification-channel, (*6)
You must install the service provider:
```php
// config/app.php
'providers' => [
...
NotificationChannels\Hooks\HooksServiceProvider::class,
],
Setting up the Hooks service
- Sign up for a developer account on Hooks site.
- Get the API Key, located in the account page.
- Create a custom alert on alerts page.
- Obtain the alert id associated with your notification, located in your alerts page. It'll be used when sending a notification.
Then, configure your Hooks API Key by adding it to the config/services.php
file:, (*7)
// config/services.php
...
'hooks' => [
'key' => env('HOOKS_API_KEY', 'YOUR HOOKS API KEY HERE')
],
...
Usage
You can now use the channel in your via()
method inside the Notification class., (*8)
``` php
use NotificationChannels\Hooks\HooksChannel;
use NotificationChannels\Hooks\HooksMessage;
use Illuminate\Notifications\Notification;, (*9)
class NewsUpdate extends Notification
{
public function via($notifiable)
{
return [HooksChannel::class];
}, (*10)
public function toHooks($notifiable)
{
$url = url('/news/' . $notifiable->id);
return HooksMessage::create()
->alertId('<Hooks Alert ID>') // Optional.
->message('Laravel 5.3 launches with the all new notifications feature!')
->url($url);
}
}, (*11)
Here's a screenshot preview of the above notification on Hooks App:
![Laravel Hooks Notification Example](https://cloud.githubusercontent.com/assets/1915268/17791360/63550c58-65b8-11e6-84d3-cc5db57a0f80.jpg)
### Routing a message
You can either send the notification by providing with the alert id to the `alertId($alertId)` method like shown in the above example or add a `routeNotificationForHooks()` method in your notifiable model:
``` php
...
/**
* Route notifications for the Hooks channel.
*
* @return int
*/
public function routeNotificationForHooks()
{
return 'YOUR ALERT ID HERE';
}
...
Available Message methods
-
alertId($alertId)
: (integer) The alert id associated with your notification, located in your alerts page.
-
message('')
: (string) The message of the notification.
-
url($url)
: (string) The related url of this notification.
Changelog
Please see CHANGELOG for more information what has changed recently., (*12)
Testing
bash
$ composer test
, (*13)
Security
If you discover any security related issues, please email syed@lukonet.com instead of using the issue tracker., (*14)
Contributing
Please see CONTRIBUTING for details., (*15)
Credits
License
The MIT License (MIT). Please see License File for more information., (*16)