$query */ #[\Illuminate\Database\Eloquent\Attributes\Scope] protected function period(Builder $query, string $period): void { if ($period == 'today') { $query->where('timestamp', '>=', \Illuminate\Support\Facades\Date::today()->timestamp); } if ($period == 'last_week') { $query->whereBetween('timestamp', [now()->subWeek()->timestamp, now()->timestamp]); } if ($period == 'last_month') { $query->whereBetween('timestamp', [now()->subMonth()->timestamp, now()->timestamp]); } } /** * @return BelongsTo */ public function user(): BelongsTo { return $this->belongsTo(User::class); } /** * @return BelongsTo */ public function room(): BelongsTo { return $this->belongsTo(Room::class); } /** * @return HasMany */ public function likes(): HasMany { return $this->hasMany(CameraLike::class); } /** * @return HasMany */ public function views(): HasMany { return $this->hasMany(CameraView::class); } /** * @return Attribute */ protected function formattedDate(): Attribute { /** @var Attribute */ return new Attribute( get: fn () => \Illuminate\Support\Facades\Date::parse($this->timestamp)->format('Y-m-d H:i'), ); } protected function casts(): array { return [ 'timestamp' => 'datetime', ]; } }