php - How to subscribe user with laravel notification channel for OneSignal -
i trying use laravel-notifications-channel/onesignal , having problems users in laravel app set receive notifications. documentation on github page not cover how user authenticates them self receive notification.
even reading on onesignal docs sending users onesignal not working me.
how set when user using our web app notified receive notifications , can send notifications them using laravel notifications?
here assignedtotask notification file:
<?php namespace app\notifications; use app\task; use illuminate\bus\queueable; use illuminate\notifications\notification; use illuminate\contracts\queue\shouldqueue; use illuminate\notifications\messages\mailmessage; use notificationchannels\onesignal\onesignalchannel; use notificationchannels\onesignal\onesignalmessage; use notificationchannels\onesignal\onesignalwebbutton; class assignedtotask extends notification { use queueable; protected $task; /** * create new notification instance. * * @return void */ public function __construct(task $task) { // $this->task = $task; } /** * notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['mail', onesignalchannel::class]; } public function toonesignal($notifiable) { return onesignalmessage::create() ->subject("your {$notifiable->service} account approved!") ->body("click here see details.") ->url('http://onesignal.com') ->webbutton( onesignalwebbutton::create('link-1') ->text('click here') ->icon('https://upload.wikimedia.org/wikipedia/commons/4/4f/laravel_logo.png') ->url('http://laravel.com') ); } /** * mail representation of notification. * * @param mixed $notifiable * @return \illuminate\notifications\messages\mailmessage */ public function tomail($notifiable) { return (new mailmessage) ->subject('you have been assigned new task') ->line('you have new task: ' . $this->task->title) ->action('view task', url('tasks/' . $this->task->id)); } /** * array representation of notification. * * @param mixed $notifiable * @return array */ public function toarray($notifiable) { return [ // ]; } }
in user model:
<?php namespace app; use illuminate\notifications\notifiable; use illuminate\foundation\auth\user authenticatable; use zizaco\entrust\traits\entrustusertrait; use hipsterjazzbo\landlord\belongstotenants; use cmgmyr\messenger\traits\messagable; class user extends authenticatable { use notifiable; use entrustusertrait; use belongstotenants; use messagable; /** * attributes mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', 'company_id' ]; /** * attributes should hidden arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', 'company_id' ]; .... public function routenotificationforonesignal() { return 'one_signal_player_id'; } public function routenotificationformail() { return $this->email_address; } }
how set , one_signal_player_id in user model user accepts notifications , can send them notifications?
edit - 2 since don't know what's happening is, let me try explain how can work onesignal
.
this push messaging system other push notification system. (fcm (google), pubnub).
how works
- first goto
onesignal.com
create account, , create app you. once create app give sdk mobile, consumers are. - now whenever consumers install , start app, notify web server own unique id , user information.
- the information received user unique player_id store in database against user.
- now when want send notification mobile app call api post notification method player_id ,
onesignal
send push notification mobile app.
edit - 1
i think understand confusion notifications onesignalchannel
flow
- you have players_ids stored in app database against every user.
- now when want push notification player, take users player_id db , push notification onesignal.
well took meaning literally. causing issue
public function routenotificationforonesignal() { return 'one_signal_player_id'; }
from error message function should have return unique id (uuid).
change return value actual player id @ onesignalchannel
that's friend.
Comments
Post a Comment