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