/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $lasts = Last::all(); foreach ($lasts as $key) { $created = new \Carbon\Carbon($key->date); $now = \Carbon\Carbon::now(); $difference = $created->diffInDays($now); $key['dateWords'] = $created->format('l, F jS, Y'); $key['datediff'] = $difference; } return view('welcome.index', ['lasts' => $lasts]); }
/** * Execute the console command. * * @return mixed */ public function handle() { $lasts = Last::all(); foreach ($lasts as $key) { $created = new \Carbon\Carbon($key->date); $now = \Carbon\Carbon::now(); $difference = $created->diffInDays($now); $key['dateWords'] = $created->format('l, F jS, Y'); $key['datediff'] = $difference; } $now = \Carbon\Carbon::now(); foreach ($lasts as $l) { if ($now > $l->lastNotify) { Mail::send('email.daysago', ['l' => $l], function ($m) { $m->from('*****@*****.**', 'The last time @samyerkes...'); $m->to('*****@*****.**', 'samyerkes')->subject('Keep going...'); }); unset($l->dateWords, $l->datediff); $l->lastNotify = \Carbon\Carbon::now()->addDays($l->notifyInteger); $l->save(); } } echo 'emails sent'; }