brand = $brand; } /** * Execute the job. * * @return void */ public function handle() { $stats = new BrandStat([ 'active' => CustomerLogin::whereBrandId($this->brand->id) ->whereDate('last_connection', '<', Carbon::now()->subMonths(6))->count(), 'inactive' => CustomerLogin::whereBrandId($this->brand->id) ->whereDate('last_connection', '>', Carbon::now()->subMonths(6))->count(), 'new_accounts' => CustomerLogin::whereBrandId($this->brand->id) ->whereDate('created_at', '<', Carbon::now()->subMonths(6))->count(), 'old_accounts' => CustomerLogin::whereBrandId($this->brand->id) ->whereDate('created_at', '>', Carbon::now()->subMonths(6))->count(), 'total_accounts' => CustomerLogin::whereBrandId($this->brand->id)->count(), 'total_opt_in' => CustomerInfo::whereBrandId($this->brand->id) ->whereOptIn(true)->count() + SingleOptin::whereBrandId($this->brand->id)->count() ]); $stats->brand()->associate($this->brand); $stats->saveOrFail(); } /** * Get the middleware the job should pass through. * * @return array */ public function middleware() { // * Dispatch randomly overlaping jobs if overlapping. return [(new WithoutOverlapping(self::JOBKEY))->releaseAfter(rand(20, 90))]; } }