I'm trying to get the total sum of downloaded files over all time and the last 24 hours for reporting purposes. The table I'm working on has a downloaded_at field which is a DATETIME type and a size field, which is the file size in bytes. In my model I'm doing the following queries:
return array(
'totalBandwidth' => self::where('downloaded_at', 'IS NOT', DB::raw('null'))->sum('size'),
'bandwidthLast24Hours' => self::where('downloaded_at', 'IS NOT', DB::raw('null'))->where('downloaded_at', '>' , new DateTime('yesterday'))->sum('size')
);
Pretty simple, however both of these queries return NULL and I can't figure out why. I've pretty much written these queries based from answers on SO and the Laravel forums.
->get()at the end of your queries?