with(['module', 'user'])->chunk(100, function ($hosts) { foreach ($hosts as $host) { $http = Http::remote($host->module->api_token, $host->module->url); $host->status = 'running'; $response = $http->post('hosts', $host->toArray()); if (!$response->successful()) { $host->status = 'error'; } $host->save(); } }); } }