withTrashed() ->where('is_proforma', 1) ->where('created_at', '<', now()->subHour()) ->cursor() ->each(function ($invoice) use ($repo) { $invoice->is_proforma = false; $repo->delete($invoice); }); Invoice::query() ->withTrashed() ->where('status_id', Invoice::STATUS_SENT) ->whereBetween('created_at', [now()->subHours(1), now()->subMinutes(10)]) ->where('balance', '>', 0) ->cursor() ->each(function ($invoice) { if (collect($invoice->line_items)->contains('type_id', 3)) { $invoice->service()->removeUnpaidGatewayFees(); } }); return; } foreach (MultiDB::$dbs as $db) { MultiDB::setDB($db); Invoice::query() ->withTrashed() ->where('is_proforma', 1) ->whereBetween('created_at', [now()->subHours(1), now()->subMinutes(10)]) ->cursor() ->each(function ($invoice) use ($repo) { $invoice->is_proforma = false; $repo->delete($invoice); }); } } public function failed($exception = null) { } }