GetGithubVersion.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Console\Commands;
  3. use Exception;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\Http;
  6. use Illuminate\Support\Facades\Log;
  7. use Illuminate\Support\Facades\Storage;
  8. class GetGithubVersion extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'cp:versioncheck:get';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Get the latest Version from Github';
  22. /**
  23. * Execute the console command.
  24. *
  25. * @return int
  26. */
  27. public function handle()
  28. {
  29. try{
  30. $latestVersion = Http::get('https://api.github.com/repos/ctrlpanel-gg/panel/tags')->json()[0]['name'];
  31. Storage::disk('local')->put('latestVersion', $latestVersion);
  32. } catch (Exception $e) {
  33. Storage::disk('local')->put('latestVersion', "unknown");
  34. Log::error($e);
  35. }
  36. return Command::SUCCESS;
  37. }
  38. }