update bugs user notification
This commit is contained in:
@@ -4,8 +4,17 @@ namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Kreait\Firebase\Messaging\CloudMessage;
|
||||
use Kreait\Laravel\Firebase\Facades\Firebase;
|
||||
use NotificationChannels\Fcm\FcmChannel;
|
||||
use NotificationChannels\Fcm\FcmMessage;
|
||||
use NotificationChannels\Fcm\FcmMessage;;
|
||||
use NotificationChannels\Fcm\Resources\AndroidConfig;
|
||||
use NotificationChannels\Fcm\Resources\AndroidFcmOptions;
|
||||
use NotificationChannels\Fcm\Resources\AndroidNotification;
|
||||
use NotificationChannels\Fcm\Resources\ApnsConfig;
|
||||
use NotificationChannels\Fcm\Resources\ApnsFcmOptions;
|
||||
use NotificationChannels\Fcm\Resources\Notification as FcmNotification;
|
||||
|
||||
|
||||
class SendNotification extends Notification
|
||||
{
|
||||
@@ -19,7 +28,7 @@ class SendNotification extends Notification
|
||||
{
|
||||
$this->title = $title;
|
||||
$this->body = $body;
|
||||
$this->data = $data;
|
||||
$this->data = is_array($data) ? $data : (array) $data; // Pastikan data adalah array
|
||||
}
|
||||
|
||||
public function via($notifiable)
|
||||
@@ -27,13 +36,55 @@ class SendNotification extends Notification
|
||||
return [FcmChannel::class];
|
||||
}
|
||||
|
||||
// public function toFcm($notifiable)
|
||||
// {
|
||||
// return FcmMessage::create()
|
||||
// ->setData($this->data)
|
||||
// ->setNotification([
|
||||
// 'title' => $this->title,
|
||||
// 'body' => $this->body,
|
||||
// ]);
|
||||
// }
|
||||
|
||||
public function toFcm($notifiable)
|
||||
{
|
||||
return FcmMessage::create()
|
||||
->setData($this->data)
|
||||
->setNotification([
|
||||
'title' => $this->title,
|
||||
'body' => $this->body,
|
||||
]);
|
||||
$deviceTokens = $notifiable->routeNotificationFor('fcm');
|
||||
$notification = [
|
||||
'title' => $this->title,
|
||||
'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);
|
||||
}
|
||||
}
|
||||
|
||||
$dataFcm = FcmMessage::create()
|
||||
->setToken($deviceTokens[0])
|
||||
->setData([])
|
||||
->setNotification(
|
||||
FcmNotification::create()
|
||||
->setTitle('ini title')
|
||||
->setBody('ini body')
|
||||
)
|
||||
->setAndroid(
|
||||
AndroidConfig::create()
|
||||
->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
|
||||
->setNotification(AndroidNotification::create()->setColor('#0A0A0A'))
|
||||
|
||||
)->setApns(
|
||||
ApnsConfig::create()
|
||||
->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
|
||||
);
|
||||
return $dataFcm;
|
||||
}
|
||||
|
||||
public function fcmProject($notifiable, $message){
|
||||
return 'app';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user