bugs fix send notification
This commit is contained in:
@@ -14,6 +14,7 @@ class NotificationToken extends Model
|
|||||||
'type',
|
'type',
|
||||||
'token',
|
'token',
|
||||||
'status',
|
'status',
|
||||||
|
'device_id'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
|
|||||||
@@ -114,6 +114,6 @@ class User extends Authenticatable
|
|||||||
|
|
||||||
public function routeNotificationForFcm()
|
public function routeNotificationForFcm()
|
||||||
{
|
{
|
||||||
return $this->notificationTokens()->pluck('token')->toArray();
|
return $this->notificationTokens()->orderBy('created_at', 'desc')->pluck('token')->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,22 +54,27 @@ class SendNotification extends Notification
|
|||||||
'body' => $this->body,
|
'body' => $this->body,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (count($deviceTokens)){
|
// if (count($deviceTokens)){
|
||||||
foreach($deviceTokens as $token) {
|
// foreach($deviceTokens as $token) {
|
||||||
$message = CloudMessage::withTarget('token', $token)
|
// $message = CloudMessage::withTarget('token', $token)
|
||||||
->withNotification($notification) // optional
|
// ->withNotification($notification) // optional
|
||||||
->withData($this->data);
|
// ->withData($this->data);
|
||||||
Firebase::messaging()->send($message);
|
// Firebase::messaging()->send($message);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// $datas = [
|
||||||
|
// 'channel_id' => 2,
|
||||||
|
|
||||||
|
// ]
|
||||||
|
|
||||||
$dataFcm = FcmMessage::create()
|
$dataFcm = FcmMessage::create()
|
||||||
->setToken($deviceTokens[0])
|
->setToken($deviceTokens[0])
|
||||||
->setData([])
|
->setData($this->data)
|
||||||
->setNotification(
|
->setNotification(
|
||||||
FcmNotification::create()
|
FcmNotification::create()
|
||||||
->setTitle('ini title')
|
->setTitle($this->title)
|
||||||
->setBody('ini body')
|
->setBody($this->body)
|
||||||
)
|
)
|
||||||
->setAndroid(
|
->setAndroid(
|
||||||
AndroidConfig::create()
|
AndroidConfig::create()
|
||||||
|
|||||||
Reference in New Issue
Block a user