withTrashed() ->where('is_proforma', 1) ->where('created_at', '<', now()->subHour()) ->cursor() ->each(function ($invoice) use ($repo) { $invoice->is_proforma = false; $repo->delete($invoice); }); return; } foreach (MultiDB::$dbs as $db) { MultiDB::setDB($db); Invoice::query() ->withTrashed() ->where('is_proforma', 1) ->where('created_at', '<', now()->subHour()) ->cursor() ->each(function ($invoice) use ($repo) { $invoice->is_proforma = false; $repo->delete($invoice); }); } } public function failed($exception = null) { } }