QueryService.php 654B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Support\Facades\DB;
  4. class QueryService
  5. {
  6. public static function queryAmount(string $table, string $title)
  7. {
  8. return DB::table($table)
  9. ->selectRaw(
  10. "COUNT(*) as amount,
  11. (SELECT COUNT(*) FROM products WHERE DATE(updated_at) = CURDATE()) as amountToday"
  12. )
  13. ->get()
  14. ->transform(
  15. fn($sale) => [
  16. "title" => $title,
  17. "amount" => $sale->amount,
  18. "amountToday" => $sale->amountToday,
  19. ]
  20. )
  21. ->first();
  22. }
  23. }