| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class Visits extends Model
- {
- protected $table = 'visits';
- protected $primaryKey = 'id';
- public $keyType = 'int';
- public $incrementing = true;
- public $timestamps = true;
- const CREATED_AT = 'created_at';
- const UPDATED_AT = 'updated_at';
- const DELETED_AT = null;
- protected $guarded = [];
- /*
- * 오늘 방문자 수
- */
- public function todayCount(): int
- {
- return $this->whereDate('created_at', now()->today())->distinct()->count('ip');
- }
- /*
- * 어제 방문자 수
- */
- public function yesterdayCount(): int
- {
- return $this->whereDate('created_at', now()->yesterday())->distinct()->count('ip');
- }
- /*
- * 누적 방문자 수
- */
- public function totalCount(): int
- {
- return $this->distinct()->count('ip');
- }
- }
|