Easily manage Expo notifications with Laravel. Support batched notifications.
Major version zero (0.y.z) is for initial development. Anything MAY change at any time. The public API SHOULD NOT be considered stable.
composer require yieldstudio/laravel-expo-notifier
You must publish the configuration file with:
php artisan vendor:publish --provider="YieldStudio\LaravelExpoNotifier\ExpoNotificationsServiceProvider" --tag="expo-notifications-config" --tag="expo-notifications-migration"
EXPO_PUSH_NOTIFICATIONS_PER_REQUEST_LIMIT
: sets the max notifications sent on a bulk request. The official documentation says the limit should be 100 but in fact it's failing. You can tweak it by setting a value under 100.EXPO_NOTIFICATIONS_ACCESS_TOKEN
: sets the Expo access token used to send notifications with an additional layer of security. You can get your access token from your Expo dashboard.
In order to use Notification, you need to declare the relation expoTokens
on your Notifiable class.
Two Trait are available to help you :
HasUniqueExpoToken
if your notifiable class can have only one expo tokenHasManyExpoToken
if your notifiable class can have many expo token
<?php
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use YieldStudio\LaravelExpoNotifier\ExpoNotificationsChannel;
use YieldStudio\LaravelExpoNotifier\Dto\ExpoMessage;
class NewSampleNotification extends Notification
{
public function via($notifiable): array
{
return [ExpoNotificationsChannel::class];
}
public function toExpoNotification($notifiable): ExpoMessage
{
return (new ExpoMessage())
// ->to($notifiable->expoTokens->pluck('value')->toArray()) if using HasManyExpoToken
->to([$notifiable->expoTokens->value])
->title('A beautiful title')
->body('This is a content')
->channelId('default');
}
}
Send database pending notifications
php artisan expo:notifications:send
Clean sent notification from database
php artisan expo:notifications:clear
Clean tickets from outdated tokens
php artisan expo:tickets:check
You may create schedules to execute these commands.
You can send notification in the next batch :
(new ExpoMessage())
->to([$notifiable->expoTokens->value])
->title('A beautiful title')
->body('This is a content')
->channelId('default')
->shouldBatch();
Don't forget to schedule the expo:notifications:send
command.
To run the tests, just run composer install
and composer test
.
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you've found a bug regarding security please mail contact@yieldstudio.fr instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.