tenant."-".$r->gallery."-".$r->year."-".$r->month."-".$r->day."-".$r->hour."-".$r->typ; if(isset($result[$key])) { $result[$key] = $result[$key] + $r->size; } else { $result[$key] = $r->size; } } //Save result in db var_dump($result); foreach ($result as $key => $trafficSize) { $split = explode("-", $key); if(empty($split[1])) { $traffic = Traffic::query() ->where("tenant", "=", (int)$split[0]) ->whereNull("gallery") ->where("year", "=", (int)$split[2]) ->where("month", "=", (int)$split[3]) ->where("day", "=", (int)$split[4]) ->where("hour", "=", (int)$split[5]) ->where("typ", "=", $this->getTyp($split[6])) ->first(); } else { $traffic = Traffic::query() ->where("tenant", "=", (int)$split[0]) ->where("gallery", "=", (int)$split[1]) ->where("year", "=", (int)$split[2]) ->where("month", "=", (int)$split[3]) ->where("day", "=", (int)$split[4]) ->where("hour", "=", (int)$split[5]) ->where("typ", "=", $this->getTyp($split[6])) ->first(); } if($traffic == null) { $traffic = new Traffic(); $traffic->tenant = $split[0]; $traffic->gallery = $split[1]; $traffic->year = $split[2]; $traffic->month =$split[3]; $traffic->day = $split[4]; $traffic->hour = $split[5]; $traffic->typ = $this->getTyp($split[6]); $traffic->date = $split[2]."-".$split[3]."-".$split[4]; } if($traffic->gallery == "") { $traffic->gallery = null; } if($traffic->tenant == "") { continue; } if($traffic->traffic != $trafficSize) { $traffic->traffic = $trafficSize; $traffic->saveOrFail(); } } } private function getTyp($typ) { if($typ == "Access") { return "s3"; } if($typ == "Cache") { return "cache"; } return "generic"; } }