where('server_id', $this->server->id) ->where(function (Builder $query) { if ($this->site) { $query->where('site_id', $this->site->id); } }); } protected function getTableColumns(): array { return [ TextColumn::make('name') ->label('Event') ->searchable() ->sortable(), TextColumn::make('created_at') ->label('Created At') ->formatStateUsing(fn ($record) => $record->created_at_by_timezone) ->sortable(), ]; } protected function applyDefaultSortingToTableQuery(Builder $query): Builder { return $query->latest('created_at'); } /** * @throws Exception */ public function getTable(): Table { return $this->table ->filters([ Filter::make('created_at') ->form([ DatePicker::make('created_from'), DatePicker::make('created_until'), ]) ->query(function (Builder $query, array $data): Builder { return $query ->when( $data['created_from'], fn (Builder $query, $date): Builder => $query->whereDate('created_at', '>=', $date), ) ->when( $data['created_until'], fn (Builder $query, $date): Builder => $query->whereDate('created_at', '<=', $date), ); }), ]) ->heading($this->label) ->actions([ Action::make('view') ->hiddenLabel() ->tooltip('View') ->icon('heroicon-o-eye') ->authorize(fn ($record) => auth()->user()->can('view', $record)) ->modalHeading('View Log') ->modalContent(function (ServerLog $record) { return view('components.console-view', [ 'slot' => $record->getContent(), 'attributes' => new ComponentAttributeBag, ]); }) ->modalSubmitAction(false) ->modalCancelActionLabel('Close'), Action::make('download') ->hiddenLabel() ->tooltip('Download') ->color('gray') ->icon('heroicon-o-archive-box-arrow-down') ->authorize(fn ($record) => auth()->user()->can('view', $record)) ->action(fn (ServerLog $record) => $record->download()), DeleteAction::make() ->hiddenLabel() ->tooltip('Delete') ->icon('heroicon-o-trash') ->color('danger') ->authorize(fn ($record) => auth()->user()->can('delete', $record)), ]) ->bulkActions( BulkActionGroup::make([ DeleteBulkAction::make() ->requiresConfirmation() ->authorize(auth()->user()->can('deleteMany', [ServerLog::class, $this->server])), ]) ); } }