trin4ik / laravel-expo-push
Laravel Expo Push Notification
Installs: 1 237
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.4|^8.0
- laravel/framework: >=8.0
README
Simple and stupid package for send push notification with expo-notification service.
No tests, no mans, no routes/controllers for get tokens from clients etc. Only channel.
If u need more, use Alymosul/laravel-exponent-push-notifications
Installation
composer require trin4ik/laravel-expo-push
php artisan vendor:publish --provider "Trin4ik\LaravelExpoPush\ExpoPushServiceProvider"
U can log query to expo notification service into database with payloads and responses.
echo "EXPO_PUSH_LOG=true" >> .env php artisan migrate
Users expo tokens
U need add method routeNotificationForExpoPush
any model, like User
, who return expo token
<?php namespace App\Models; // ... class User extends Authenticatable { use Notifiable; // ... public function routeNotificationForExpoPush () { return $this->expo_token; // like ExponentPushToken[XXXXXXX_XXXXXXXXXXXXXX] } }
Change log database
By default, log write to expo_push_notification
table, u can change it in 2 step:
- extends
Trin4ik\LaravelExpoPush\Models\ExpoPushNotification.php
like:
<?php namespace App\Models; class ExpoPushNotification extends Trin4ik\LaravelExpoPush\Models\ExpoPushNotification { protected $table = 'my_custom_notifications_table'; }
- change in
config/expo-push.php
log/driver/instance
to your new model:
return [ // ... 'log' => [ // ... 'driver' => [ // ... 'instance' => \App\Models\ExpoPushNotification::class ] ] ];
Usage
Like other channels, u need create Notification
php artisan make:notification PushTest
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; use Trin4ik\LaravelExpoPush\Channels\ExpoPushChannel; use Trin4ik\LaravelExpoPush\ExpoPush; class PushTest extends Notification implements ShouldQueue { use Queueable; public function via($notifiable) { return [ExpoPushChannel::class]; } public function toExpoPush($notifiable) { return ExpoPush::create() ->badge(1) ->title("Congratulations!") ->body("Your " . $notifiable->email . " account was approved!"); } }
for more information about
ExpoPush::create
methods, look down
And usage like:
<?php use App\Notifications\PushTest; use App\Models\User; // ... $user = User::find(1); $user->notify(new PushTest);
ExpoPush::create
methods
More info on Expo notification service message format
If new SDK release new format, u can create PR or use toArray()
method in your Notification, like:
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; use Trin4ik\LaravelExpoPush\Channels\ExpoPushChannel; class PushTest extends Notification implements ShouldQueue { use Queueable; public function via($notifiable) { return [ExpoPushChannel::class]; } public function toArray($notifiable) { return [ 'badge' => 1, 'title' => "Congratulations!", 'body' => "Your " . $notifiable->email . " account was approved!", 'new_expo_notification_param' => true ]; } }
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email trin4ik@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Thanks
❤️ This package was generated using the Laravel Package Boilerplate.
❤️ More code spizjeno from Alymosul/laravel-exponent-push-notifications