$instance->uuid, 'version' => $instance->current_version, 'contacts' => Contact::count(), ]; $data['uuid'] = $instance->uuid; $data['version'] = $instance->current_version; $data['contacts'] = Contact::all()->count(); // Send the JSON try { $client = new Client(); $response = $client->post(config('monica.weekly_ping_server_url'), [ 'json' => $data, ]); } catch (\GuzzleHttp\Exception\ConnectException $e) { return; } catch (\GuzzleHttp\Exception\TransferException $e) { return; } // Receive the JSON $json = json_decode($response->getBody(), true); if (json_last_error() !== JSON_ERROR_NONE) { // JSON is invalid // The function json_last_error returns the last error occurred during the JSON encoding and decoding return; } // make sure the JSON has all the fields we need if (! isset($json['latest_version']) || ! isset($json['new_version']) || ! isset($json['number_of_versions_since_user_version'])) { return; } if ($json['latest_version'] != $instance->current_version) { $instance->latest_version = $json['latest_version']; $instance->latest_release_notes = $json['notes']; $instance->number_of_versions_since_current_version = $json['number_of_versions_since_user_version']; $instance->save(); } else { $instance->latest_release_notes = null; $instance->number_of_versions_since_current_version = null; $instance->save(); } } }