bugs fix send notification

This commit is contained in:
Linksehat Staging Server
2024-06-03 09:09:16 +07:00
parent 5e0d0cac1b
commit 4b7337f7cb
3 changed files with 18 additions and 12 deletions

View File

@@ -14,6 +14,7 @@ class NotificationToken extends Model
'type',
'token',
'status',
'device_id'
];
protected $hidden = [

View File

@@ -114,6 +114,6 @@ class User extends Authenticatable
public function routeNotificationForFcm()
{
return $this->notificationTokens()->pluck('token')->toArray();
return $this->notificationTokens()->orderBy('created_at', 'desc')->pluck('token')->toArray();
}
}

View File

@@ -54,22 +54,27 @@ class SendNotification extends Notification
'body' => $this->body,
];
if (count($deviceTokens)){
foreach($deviceTokens as $token) {
$message = CloudMessage::withTarget('token', $token)
->withNotification($notification) // optional
->withData($this->data);
Firebase::messaging()->send($message);
}
}
// if (count($deviceTokens)){
// foreach($deviceTokens as $token) {
// $message = CloudMessage::withTarget('token', $token)
// ->withNotification($notification) // optional
// ->withData($this->data);
// Firebase::messaging()->send($message);
// }
// }
// $datas = [
// 'channel_id' => 2,
// ]
$dataFcm = FcmMessage::create()
->setToken($deviceTokens[0])
->setData([])
->setData($this->data)
->setNotification(
FcmNotification::create()
->setTitle('ini title')
->setBody('ini body')
->setTitle($this->title)
->setBody($this->body)
)
->setAndroid(
AndroidConfig::create()