public function email_notice() { $now = new \DateTime('now'); $funds = Fund::where('notice_1', $now->format('Y-m-d'))->get(); foreach ($funds as $fund) { $applications = $fund->applications; foreach ($applications as $application) { if (!in_array($application->status, ["approved_project_finished", "rejected"])) { $data = array(); $data['application'] = $application; $data['user'] = $application->user; $data['fund'] = $fund; if ($now == $fund->notice1) { Mail::queue('emails.autonotify', $data, function ($message) use($data) { $message->to($data['user']->email, $data['user']->name)->subject('Notification for first progress report submission at nurse.tu.ac.th'); }); } else { if ($now == $fund->notice2) { Mail::queue('emails.autonotify', $data, function ($message) use($data) { $message->to($data['user']->email, $data['user']->name)->subject('Notification for second progress report submission at nurse.tu.ac.th'); }); } else { if ($now == $fund->notice3) { Mail::queue('emails.autonotify', $data, function ($message) use($data) { $message->to($data['user']->email, $data['user']->name)->subject('Notification for closing project report submission at nurse.tu.ac.th'); }); } else { if ($now == $fund->notice4) { Mail::queue('emails.autonotify', $data, function ($message) use($data) { $message->to($data['user']->email, $data['user']->name)->subject('Notification for project extended report submission at nurse.tu.ac.th'); }); } } } } echo "<p>Notification message sent to {$application->user->email}</p>\n"; } } } }
public function fundAgo() { return view('funds.fund_ago', ['funds' => Fund::where('apply_end', '<', new \DateTime('today'))->get()]); }