/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { /* * Let us know if there is something new :) */ // check if there is a new error $schedule->call(function () { // get new errors $new_errors = Error::cronUnseen()->get(); if (!$new_errors->isEmpty()) { Mail::send('emails.errors', ['errors' => $new_errors], function ($message) { $message->from('*****@*****.**', 'Notification | MyGrades'); $message->to("*****@*****.**", $name = null); $message->subject("New errors reported"); }); // mark them as seen DB::table('errors')->whereNull('cron_seen')->update(['cron_seen' => Carbon::now()]); } })->hourly(); // check if there is a new wish $schedule->call(function () { // get new errors $new_wishes = Wish::cronUnseen()->get(); if (!$new_wishes->isEmpty()) { Mail::send('emails.wishes', ['wishes' => $new_wishes], function ($message) { $message->from('*****@*****.**', 'Notification | MyGrades'); $message->to("*****@*****.**", $name = null); $message->subject("New wishes"); }); // mark them as seen DB::table('wishes')->whereNull('cron_seen')->update(['cron_seen' => Carbon::now()]); } })->hourly(); }
/** * Saves the editing of wishes. An admin can select a wish as done and/or written. * * @return \Illuminate\Http\RedirectResponse */ public function updateAdmin() { foreach (Input::all() as $key => $value) { // done checked for specific wish if (starts_with($key, 'done') && intval($value) === 1) { $wish_id = intval(str_replace('done', '', $key)); $wish = Wish::find($wish_id); // update wish $wish->done = true; $wish->save(); } elseif (starts_with($key, 'written') && intval($value) === 1) { // written checked for specifc wish $wish_id = intval(str_replace('written', '', $key)); $wish = Wish::find($wish_id); // update wish $wish->written = true; $wish->save(); } } // back to form return redirect()->route('adminWishes'); }