/**
  * Execute the job.
  *
  * @return void
  */
 public function handle(SendMailInterface $mail)
 {
     $ticketObj = new Ticket();
     $ticket = $ticketObj->getTicketById($this->ticket->id);
     $select = ['u.name', 'u.email'];
     $followers = DB::table('ticket_followers as tf')->select($select)->join('users as u', 'u.id', '=', 'tf.user_id')->where('tf.ticket_id', $this->ticket->id)->get();
     // \Log::info(print_r($ticket, 1));
     // send email to user who was assigned the ticket
     $mail->mail(['from' => '*****@*****.**', 'fromName' => 'Amitav Roy', 'to' => $ticket->users[0]->email, 'toName' => 'Amitav Roy', 'subject' => '[New ticket] #' . $ticket->id . ' - ' . $ticket->title, 'mailBody' => view('mails.ticket-assigned', compact('ticket'))]);
     // sending mail to all the followers
     if ($followers) {
         foreach ($followers as $follower) {
             // user who is assigned should not get the email again if he is
             // also in the followers list
             if ($ticket->users[0]->email != $follower->email) {
                 $mail->mail(['from' => '*****@*****.**', 'fromName' => 'Amitav Roy', 'to' => $follower->email, 'toName' => $follower->name, 'subject' => '[New ticket to follow] #' . $ticket->id . ' - ' . $ticket->title, 'mailBody' => view('mails.ticket-assigned', compact('ticket'))]);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function getTicketById($id)
 {
     $ticket = new Ticket();
     return response(['data' => $ticket->getTicketById($id)], 200);
 }