OverViewController.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Payment;
  5. use App\Models\Server;
  6. use App\Models\User;
  7. use Illuminate\Support\Facades\Cache;
  8. class OverViewController extends Controller
  9. {
  10. public const TTL = 86400;
  11. public function index()
  12. {
  13. $userCount = Cache::remember('user:count', self::TTL, function () {
  14. return User::query()->count();
  15. });
  16. $creditCount = Cache::remember('credit:count', self::TTL, function () {
  17. return User::query()->sum('credits');
  18. });
  19. $paymentCount = Cache::remember('payment:count', self::TTL, function () {
  20. return Payment::query()->count();
  21. });
  22. $serverCount = Cache::remember('server:count', self::TTL, function () {
  23. return Server::query()->count();
  24. });
  25. return view('admin.overview.index', [
  26. 'serverCount' => $serverCount,
  27. 'userCount' => $userCount,
  28. 'paymentCount' => $paymentCount,
  29. 'creditCount' => number_format($creditCount, 2, '.', ''),
  30. ]);
  31. }
  32. }