PATH:
home
/
rwabteecom
/
project_11
/
app
/
Notifications
/
User
/
Editing: SendPushNotification.php
<?php namespace App\Notifications\User; use App\Helpers\Firebase; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; use Kutia\Larafirebase\Messages\FirebaseMessage; class SendPushNotification extends Notification { use Queueable; protected $title; protected $message; protected $device_token; /** * Create a new notification instance. */ public function __construct($title,$message,$device_token) { $this->title = $title; $this->message = $message; $this->device_token = $device_token; } /** * Get the notification's delivery channels. * * @return array<int, string> */ public function via(object $notifiable): array { return ['firebase','database']; } /** * Get the mail representation of the notification. */ public function toMail(object $notifiable): MailMessage { return (new MailMessage) ->line('The introduction to the notification.') ->action('Notification Action', url('/')) ->line('Thank you for using our application!'); } public function toFirebase($notifiable) { $title=auth()->user()->default_lang == "ar" ? $this->title['ar'] : $this->title['en'] ; $message=auth()->user()->default_lang == "ar" ? $this->message['ar'] : $this->message['en'] ; return Firebase::sendNotificationToDeviceToken( $title,$message,$this->device_token); } /** * Get the array representation of the notification. * * @return array<string, mixed> */ public function toArray(object $notifiable): array { return [ 'title'=>$this->title, 'message'=>$this->message, ]; } }
SAVE
CANCEL