public static function getTodayStatistics() { $statisticsDetails = EnterpriseArticleStatistics::where('date', Carbon::now()->format('Y-m-d'))->get(); if ($statisticsDetails) { $statisticsDetails = $statisticsDetails->toArray(); } else { $statisticsDetails = []; } foreach ($statisticsDetails as &$details) { $details['article_type'] = ArticleType::find($details['article_type_id'])->toArray(); } return $statisticsDetails; }
/** * @param $articleType */ public function updateArticleStatistics($articleTypeId) { $date = Carbon::now()->toDateString(); $statistics = EnterpriseArticleStatistics::where('date', $date)->where('article_type_id', $articleTypeId)->first(); if (!$statistics) { $statistics = new EnterpriseArticleStatistics(); $statistics->article_type_id = $articleTypeId; $statistics->date = $date; $statistics->count = 0; } /*if>*/ $statistics->count += 1; $statistics->save(); }