laravel-notification maintained by relaylayerio
RelayLayer notification channel for Laravel
Send a Laravel notification through RelayLayer with a secret key from App / keys.
The in-app inbox and mobile push stay on the RelayLayer SDKs. This package only calls the notifications API.
Install
composer require relaylayerio/laravel-notification
The service provider is discovered automatically. Publish the config if you want it in your app:
php artisan vendor:publish --tag=relaylayer-notification-config
Set the environment the secret key belongs to:
RELAYLAYER_URL=https://api.relaylayer.io
RELAYLAYER_KEY=rl_test_...
Use rl_live_... only on production.
Send
use Illuminate\Notifications\Notification;
use RelayLayer\LaravelNotification\RelayLayerMessage;
class OrderReady extends Notification
{
public function via(object $notifiable): array
{
return ['relaylayer'];
}
public function toRelayLayer(object $notifiable): RelayLayerMessage
{
return (new RelayLayerMessage)
->title('Your order is ready')
->body('Pick it up at the counter.')
->channels(['in_app', 'email']);
}
}
Route the notification to the subscriber id your app already uses:
Notification::route('relaylayer', 'user_42')->notify(new OrderReady);
If the message includes an email, phone, name, or locale, the channel upserts that subscriber before it sends. Otherwise the subscriber must already exist.
A template key works the same way as the API:
return (new RelayLayerMessage)
->template('order-ready', ['name' => 'Ada'])
->channels(['email']);
Plan limits still apply. A subscriber over the plan cap, or a send over the monthly notification cap, comes back as a 422 from the API and throws Illuminate\Http\Client\RequestException.