/** * Execute the console command. * * @return mixed */ public function fire() { $log = new Process(); $log->name = "make-history"; $log->status = "running"; $log->save(); $today = Carbon::today(); $topToday = array(); $newspapers = Newspaper::select('id')->get(); $tags = Tag::select('id')->get(); foreach ($newspapers as $key => $n) { $top = $this->getTopLink($today, $n->id, false); if ($top) { $topToday[] = $top; } } foreach ($tags as $key => $t) { $top = $this->getTopLink($today, false, $t->id); if ($top) { $topToday[] = $top; } } $topToday = array_unique($topToday); //Remove links for today History::where('date', '=', $today)->delete(); //Save history foreach ($topToday as $key => $t) { $this->info($t->title); try { $h = new History(); $h->id_ref = $t->id; unset($t->id); $h->fill($t->toArray()); $h->date = $today; $h->save(); } catch (Exception $e) { } } $log->status = "finished"; $log->save(); }
public function getNewspapers() { return Response::json(Newspaper::select('id', 'name', 'logo')->orderBy('name', 'ASC')->get()); }