where('os', $request->os)->first(); if (! $app_version) { return $this->versionNotFound(); } if ($request->version === $app_version->version) { return $this->latestVersion($app_version); } if ($request->version < $app_version->version && $app_version->important) { return $this->requiredToUpdate($app_version); } if ((int) $request->version < (int) $app_version->version) { return $this->optionalToUpdate($app_version); } return $this->versionNotFound(); } /** * Latest version */ public function latestVersion(AppVersion $app_version): JsonResponse { return response()->json([ 'update' => 'latest', 'notes' => sprintf('You are using the latest version of the app (%s).', $app_version->version), ]); } /** * Required to update */ public function requiredToUpdate(AppVersion $app_version): JsonResponse { return response()->json([ 'update' => 'required', 'notes' => sprintf('A critical update is available. Please update to the latest version (%s).', $app_version->version), ]); } /** * Update not required, but should be */ public function optionalToUpdate(AppVersion $app_version): JsonResponse { return response()->json([ 'update' => 'optional', 'notes' => sprintf('A new version is available. Please update to the latest version (%s).', $app_version->version), ]); } /** * App version not found */ public function versionNotFound(): JsonResponse { return response()->json([ 'update' => 'version-not-found', 'notes' => 'The version is not recognized (e.g., development build).', ]); } }