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) ->where('created_at', '<', now()->subMinutes(30)) ->where('balance', '>', 0) ->whereJsonContains('line_items', ['type_id' => '3']) ->cursor() ->each(function ($invoice) { $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); }); Invoice::query() ->withTrashed() ->where('status_id', Invoice::STATUS_SENT) ->where('created_at', '<', now()->subMinutes(30)) ->where('balance', '>', 0) ->whereJsonContains('line_items', ['type_id' => '3']) ->cursor() ->each(function ($invoice) { $invoice->service()->removeUnpaidGatewayFees(); }); } } public function failed($exception = null) { } }