Generic query

1 month ago

adminbmbc

test

Code

use App\Models\Statistics\Analytic\GaData;
use DB;

GaData::query()
  ->where('hostname','epresspack.com')
  ->select(
  	'date',
  	'hostname',
  	 DB::raw('SUM(page_views) as page_views'),
     DB::raw('SUM(sessions) as sessions'),
     DB::raw('SUM(users) as users'),
	)
   ->groupBy(['date', 'hostname'])
   ->orderBy('date', 'ASC')
   ->take(2)
   ->get();

Output

=> Illuminate\Database\Eloquent\Collection {#1075
     all: [
       App\Models\Statistics\Analytic\GaData {#1074
         date: "2019-03-19",
         hostname: "epresspack.com",
         page_views: "2274",
         sessions: "2168",
         users: "2230",
       },
       App\Models\Statistics\Analytic\GaData {#1073
         date: "2019-03-20",
         hostname: "epresspack.com",
         page_views: "4735",
         sessions: "4656",
         users: "4711",
       },
     ],
   }
HELO: Local email testing for your desktop!