%PDF- %PDF-
Direktori : /var/www/html/diaspora/api/app/Notifications/ |
Current File : /var/www/html/diaspora/api/app/Notifications/NotifyUsersForEventComingUp.php |
<?php namespace App\Notifications; use App\Models\Device; use App\Models\Event; use Benwilkins\FCM\FcmMessage; use Carbon\Carbon; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; class NotifyUsersForEventComingUp extends Notification implements ShouldQueue { use Queueable; /** * @var Event */ private $event; /** * @var int */ private $badge; /** * Create a new notification instance. * * @param Event $event * @param int $badge */ public function __construct(Event $event, $badge = 1) { $this->event = $event; $this->badge = $badge; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['fcm']; } /** * @param Device $device * @return FcmMessage */ public function toFcm(Device $device) { $message = new FcmMessage(); $message->content([ 'badge' => $this->badge, 'title' => $this->event->getTranslation($device->language, true)->title, 'body' => Carbon::parse($this->event->when)->format('H:i') . " @ " . $this->event->getTranslation($device->language, true)->location, ]); $message->data([ 'event_id' => $this->event->id, ]); $message->priority(FcmMessage::PRIORITY_HIGH); return $message; } }