Back | Home
الـ Path الحالي: /home/picotech/domains/instantly.picotech.app/public_html/public/uploads/../../././app/./Listeners
الملفات الموجودة في هذا الـ Path:
.
..
MailEventListener.php
SendMailListener.php

مشاهدة ملف: MailEventListener.php

<?php

namespace App\Listeners;

use App\Events\MailEvent;
use App\Models\Campaign;
use App\Models\EmailQueue;
use App\Models\MessageLog;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;

class MailEventListener implements ShouldQueue
{

    use InteractsWithQueue;

    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  \App\Events\MailEvent  $event
     * @return void
     */
    public function handle(MailEvent $event)
    {
        $campaignId = $event->campaign_id;
        $email_queue_id = $event->email_queue_id;
        $emailQueue=EmailQueue::find($email_queue_id);
        if(!$emailQueue) return;

        $campaign = Campaign::where('id', $campaignId)->first();
        if ($campaign) {
            $messageLog = MessageLog::where('random_ref_key', $emailQueue->random_ref_key)->where('campaign_id', $campaign->id)->first();
        } else {
            $messageLog = MessageLog::where('random_ref_key', $emailQueue->random_ref_key)->first();
        }
        if ($messageLog) {
            if($event->type=='opened'){
                $messageLog->is_open = 'yes';
            }elseif ($event->type=='clicked'){
                $messageLog->is_clicked = 'yes';
            }elseif ($event->type=='bounced'){
                $messageLog->is_bounced = 'yes';
            }
            $messageLog->save();
        }

        dd($messageLog);
    }
}