Пример #1
0
 public function allowBackdateEntry(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' => $id, 'backdate' => $date, 'otp' => $otp];
         // add the backdate entry
         $backdateId = DB::table('backdate_timeentry')->insertGetId(['user_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' => $backdateId, 'commentable_type' => 'backdate_timeentry']);
         }
     }
     // send the email to each developer
     foreach ($data as $entry) {
         $user = User::find($entry['user_id']);
         $comment = '';
         if ($request->input('comment')) {
             $comment = $request->input('comment');
         }
         $mail->mail(['from' => '*****@*****.**', 'fromName' => 'Amitav Roy', 'to' => $user->email, 'toName' => $user->name, 'subject' => 'Make backdate entry', 'mailBody' => view('mails.backdate-mail', compact('entry', 'comment'))]);
     }
     $timeEntryObj = new TimeEntry();
     $backdate_entries = $timeEntryObj->getLatestBackdateTimeEntries();
     return response($backdate_entries, 200);
 }