Initialize repo and add session changes (2025-09-08)
This commit is contained in:
40
app/Filament/Widgets/EventsActiveToday.php
Normal file
40
app/Filament/Widgets/EventsActiveToday.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class EventsActiveToday extends BaseWidget
|
||||
{
|
||||
protected static ?string $heading = 'Events active today';
|
||||
protected ?string $pollingInterval = '60s';
|
||||
|
||||
public function table(Tables\Table $table): Tables\Table
|
||||
{
|
||||
$today = Carbon::today()->toDateString();
|
||||
$query = DB::table('events as e')
|
||||
->leftJoin('photos as p', function ($join) use ($today) {
|
||||
$join->on('p.event_id', '=', 'e.id')
|
||||
->whereRaw("date(p.created_at) = ?", [$today]);
|
||||
})
|
||||
->where('e.is_active', 1)
|
||||
->whereDate('e.date', '<=', $today)
|
||||
->selectRaw('e.id, e.slug, e.name, e.date, COUNT(p.id) as uploads_today')
|
||||
->groupBy('e.id', 'e.slug', 'e.name', 'e.date')
|
||||
->orderBy('e.date', 'desc')
|
||||
->limit(10);
|
||||
|
||||
return $table
|
||||
->query($query)
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->label('#')->width('60px'),
|
||||
Tables\Columns\TextColumn::make('slug')->label('Slug')->searchable(),
|
||||
Tables\Columns\TextColumn::make('date')->date(),
|
||||
Tables\Columns\TextColumn::make('uploads_today')->label('Uploads today')->numeric(),
|
||||
])
|
||||
->paginated(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user