Viewing File: /home/ubuntu/vedadeals-backend-base/app/Notifications/BellNotification.php

<?php

namespace App\Notifications;

use Exception;
use Illuminate\Bus\Queueable;
use Benwilkins\FCM\FcmMessage;
use Illuminate\Notifications\Notification;
use Akaunting\Setting\Facade as Setting;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class BellNotification extends Notification
{
    use Queueable;

    protected $data;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['fcm'];
    }

    /**
     * Bell notifications for the FCM channel.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toFcm($notifiable)
    {

        try {

            $message = new FcmMessage();

            $message->setHeaders([
                'project_id'    =>  env('FCM_SENDER_ID')
            ])->content([
                'title'        => Setting::get('site_name', 'PoshMarkets'),
                'body'         => $this->data->body,
                'sound'        => asset('push_notification.wav'),
                'icon'         => Setting::get('site_logo'),
                'click_action' => $this->data->action,
            ])->data([
                'data' => $this->data->push_data
            ])
                ->to($this->data->device_token)
                ->priority(FcmMessage::PRIORITY_HIGH);

            info("Sending Bell Notification To : " . $this->data->device_token);

            return $message;
        } catch (Exception $e) {

            info("Bell Notification Error :" . $e->getMessage());
        }
    }
}
Back to Directory File Manager