/**
  * 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'))]);
             }
         }
     }
 }
 public function allowRequestBackdateEntry(Request $request, SendMailInterface $mail)
 {
     // return $request->all();
     $date = Carbon::parse($request->input('date'));
     $userIds = $request->input('users');
     $data = [];
     foreach ($userIds as $id) {
         $otp = uniqid();
         // create the data
         $data[] = ['user_id' => Auth::user()->id, 'project_manager_id' => $id, 'backdate' => $date, 'otp' => $otp];
         // add the backdate entry
         $requestBackdateId = DB::table('backdate_requests')->insertGetId(['user_id' => Auth::user()->id, 'project_manager_id' => $id, 'backdate' => $date, 'otp' => $otp]);
         // make an entry if the comment is added
         if ($request->input('comment')) {
             $comment = Comment::create(['user_id' => Auth::user()->id, 'comment' => $request->input('comment'), 'parent_id' => 0, 'thread' => '', 'status' => 1]);
             DB::table('commentables')->insert(['comment_id' => $comment->id, 'commentable_id' => $requestBackdateId, 'commentable_type' => 'backdate_request']);
         }
     }
     // send the email to each developer
     foreach ($data as $entry) {
         $user = User::find($entry['project_manager_id']);
         $comment = '';
         if ($request->input('comment')) {
             $comment = $request->input('comment');
         }
         $mail->mail(['from' => '*****@*****.**', 'fromName' => 'Amitav Roy', 'to' => $user->email, 'toName' => $user->name, 'subject' => 'Request backdate entry', 'mailBody' => view('mails.backdate-mail', compact('entry', 'comment'))]);
     }
     $timeEntryObj = new TimeEntry();
     $request_backdate_entries = $timeEntryObj->getLatestRequestBackdateTimeEntries();
     return response($request_backdate_entries, 200);
 }