UPDATE: It seems like the Hooks service is no longer active, hence, this project has been archived.
This package makes it easy to send notifications using Hooks with Laravel 5.3.
Hooks API lets you send a notification to all users subscribed to your custom alert.
You can install the package via composer:
composer require lukonet/laravel-hooks-notification-channel
You must install the service provider:
// config/app.php
'providers' => [
...
NotificationChannels\Hooks\HooksServiceProvider::class,
],
- 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:
// config/services.php
...
'hooks' => [
'key' => env('HOOKS_API_KEY', 'YOUR HOOKS API KEY HERE')
],
...
You can now use the channel in your via()
method inside the Notification class.
use NotificationChannels\Hooks\HooksChannel;
use NotificationChannels\Hooks\HooksMessage;
use Illuminate\Notifications\Notification;
class NewsUpdate extends Notification
{
public function via($notifiable)
{
return [HooksChannel::class];
}
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);
}
}
Here's a screenshot preview of the above notification on Hooks App:
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:
...
/**
* Route notifications for the Hooks channel.
*
* @return int
*/
public function routeNotificationForHooks()
{
return 'YOUR ALERT ID HERE';
}
...
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.
Please see CHANGELOG for more information what has changed recently.
$ composer test
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.