HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/ghayatcom/ghayatcom-api/app/Notifications/AppointmentCreateNotify.php
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use App\Channels\FcmChannel;
use App\Channels\Fcm;
use Illuminate\Support\Facades\Mail;
use App\Mail\PatientAppointmentReqToDoctor as Mailable;
use App\Channels\PusherChannel;
use App\Channels\Pusher;
use App\Helpers\GeneralHelper;

class AppointmentCreateNotify extends Notification implements ShouldQueue
{
    use Queueable;
    private $detail, $email_detail, $fcm_detail, $pusher, $inapp_notification;
    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($detail)
    {
        $this->detail = $detail;
        $this->email_detail = (isset($detail['mail'])) ? $detail['mail'] : [];
        $this->fcm_detail = (isset($detail['fcm'])) ? $detail['fcm'] : [];
        $this->pusher = (isset($detail['pusher'])) ? $detail['pusher'] : [];
        $this->inapp_notification = (isset($detail['inapp'])) ? $detail['inapp'] : [];
        unset($this->detail['mail']);
        unset($this->detail['fcm']);
        unset($this->detail['pusher']);
        if(isset($detail['inapp'])){
            unset($this->detail['inapp']);
        }
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        if(!empty($this->email_detail)) {
            return ['database', FcmChannel::class,PusherChannel::class,'mail'];//'mail', FcmChannel::class, 'mail',
        } else {
            return ['database', FcmChannel::class,PusherChannel::class];
        }
    }


    public function toFcm($notifiable)
    {
        if(!empty($this->fcm_detail)) {
            return (new Fcm())->triggerFcm($this->fcm_detail);
        }
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return mixed  Mailable
     */
    public function toMail($notifiable)
    {
        if(!empty($this->email_detail)) {
            GeneralHelper::setMailConfig();
            return (new Mailable($this->email_detail))->to($this->email_detail['email']);
        }
    }

      /**
     * Get the array representation of the notification.
     */
    public function toDatabase($notifiable)
    {
        if(!empty($this->inapp_notification)) {
            return [
                [
                'title' => $this->inapp_notification['in_app_title'],
                'message' =>  $this->inapp_notification['in_app_message'],
                'appointment_id' => $this->inapp_notification['appointment_id'],
                ]
            ];
        } else {
            return [];
        }
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            $this->detail
        ];
    }
    public function toPusher($notifiable)
    {
        return (new Pusher())->trigger($this->pusher);
    }
}