feat: Enhance Filament Widgets
This commit is contained in:
@@ -4,8 +4,8 @@ namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Models\Event;
|
||||
|
||||
class EventsActiveToday extends BaseWidget
|
||||
{
|
||||
@@ -15,20 +15,19 @@ class EventsActiveToday extends BaseWidget
|
||||
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)
|
||||
->query(
|
||||
Event::query()
|
||||
->where('is_active', true)
|
||||
->whereDate('date', '<=', $today)
|
||||
->withCount([
|
||||
'photos as uploads_today' => function ($q) use ($today) {
|
||||
$q->whereDate('created_at', $today);
|
||||
},
|
||||
])
|
||||
->orderByDesc('date')
|
||||
->limit(10)
|
||||
)
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->label('#')->width('60px'),
|
||||
Tables\Columns\TextColumn::make('slug')->label('Slug')->searchable(),
|
||||
|
||||
Reference in New Issue
Block a user