/** * Execute the console command. * * @return mixed */ public function handle(Cache $cache) { $this->info('Calculating stats >>>>>'); $expiresAt = Carbon::now()->addMinutes(10); $tickets = Ticket::withTrashed()->get(); $openTickets = $tickets->filter(function ($ticket) { return !$ticket->trashed(); }); $cache->put('tickets.open', $openTickets->count(), $expiresAt); $cache->put('tickets.total', $tickets->count(), $expiresAt); $this->info('Calculation done and results are cached'); }
public function getStatistic() { return response(['open' => Ticket::count(), 'total' => Ticket::withTrashed()->count()], 200); }