-
app/Models/DailyView.php
Open in GitHubuse Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; class DailyView extends Model { // ... public function scopeForUser(Builder $query): void { if (auth()->user()->isAdministrator()) { return; } $presentationIds = auth()->user()->presentations()->pluck('id'); $query->whereIn('presentation_id', $presentationIds); } // ... }
-
app/Filament/Widgets/ViewStats.php
Open in GitHubuse App\Models\DailyView; use Filament\Widgets\StatsOverviewWidget as BaseWidget; class ViewStats extends BaseWidget { // ... private function dailyViews(): Stat { $views = DailyView::forUser() ->stats(presentationId: $this->filters['presentation_id']) ->get(); // ... } private function aggregateViews(bool $withinRange = false): Stat { $views = AggregateView::forUser() ->stats( presentationId: $this->filters['presentation_id'], startDate: $withinRange ? $this->filters['start_date'] : null, endDate: $withinRange ? $this->filters['end_date'] : null, )->get(); // ... } }