You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace App\Listeners;
use App\Events\TaskCreate; use App\Models\Task; use App\Models\User; use App\Utilities\HelperClass\NotificationHelper;
class TaskCreateNotif { /** * @var NotificationHelper */ public $helper;
/** * Create the event listener. * * @return void */ public function __construct(NotificationHelper $helper) { $this->helper = $helper; }
/** * Handle the event. * * @param TaskCreate $event * @return void */ public function handle(TaskCreate $event) { $payload = $event->message;
if ($payload->data->original->assignee_id !== null) { $this->assigneeNotifHandler($payload); } if ($payload->data->original->approver_id !== null) { $this->approverNotifHandler($payload); } }
public function assigneeNotifHandler($payload) { $user = User::findOrFail($payload->data->original->assignee_id); $task = Task::findOrFail($payload->data->original->id);
$this->helper->makeNotif($payload, 'assignee', ['task' => $task->title]) ->sendNotifications($user, 'critical'); }
public function approverNotifHandler($payload) { $user = User::findOrFail($payload->data->original->approver_id); $task = Task::findOrFail($payload->data->original->id);
$this->helper->makeNotif($payload, 'approver', ['task' => $task->title]) ->sendNotifications($user, 'critical'); } }
|