size; $currentTraffic = DB::select("SELECT SUM(size) AS size FROM `go-mysql-admin`.access WHERE tenant = 1 AND created_at >= NOW() - INTERVAL 1 DAY;")[0]->size; $monthlyTraffic = DB::select("SELECT SUM(traffic) AS `traffic` FROM traffic WHERE `year` = 2021 AND `month` = 1 and tenant = 1;")[0]->traffic; $lastDaysTreffic = Traffic::getLastDays(7); $lastDaysSize = Storage::getLastDays(7); return view("dashboard.index", [ "currentSize" => $this->human_filesize($currentSize), "currentTraffic" => $this->human_filesize($currentTraffic), "monthlyTraffic" => $this->human_filesize($monthlyTraffic), "lastDaysTreffic" => $lastDaysTreffic, "lastDaysSize" => $lastDaysSize ]); } private function human_filesize($bytes, $decimals = 2) { $size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB'); $factor = floor((strlen($bytes) - 1) / 3); return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor]; } }