Visits.php 910 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Visits extends Model
  5. {
  6. protected $table = 'visits';
  7. protected $primaryKey = 'id';
  8. public $keyType = 'int';
  9. public $incrementing = true;
  10. public $timestamps = true;
  11. const CREATED_AT = 'created_at';
  12. const UPDATED_AT = 'updated_at';
  13. const DELETED_AT = null;
  14. protected $guarded = [];
  15. /*
  16. * 오늘 방문자 수
  17. */
  18. public function todayCount(): int
  19. {
  20. return $this->whereDate('created_at', now()->today())->distinct()->count('ip');
  21. }
  22. /*
  23. * 어제 방문자 수
  24. */
  25. public function yesterdayCount(): int
  26. {
  27. return $this->whereDate('created_at', now()->yesterday())->distinct()->count('ip');
  28. }
  29. /*
  30. * 누적 방문자 수
  31. */
  32. public function totalCount(): int
  33. {
  34. return $this->distinct()->count('ip');
  35. }
  36. }