simedkom/app/Filament/Resources/Visitors/VisitorResource.php
Yoga Pangestu 6fe5e81717 refactor: add type hinting to closures and fix logic errors in Filament codebase
- Added comprehensive parameter and return type hinting to closures across various Filament resources, actions, and relation managers to improve type safety and static analysis.
- Fixed logic in ReportRelationManager where report count was incorrectly compared, preventing the 'Buat Laporan' button from showing correctly.
- Corrected namespaces for RepeatableEntry and TextEntry in ViewCooperation (changed from Filament\Schemas to Filament\Infolists).
- Fixed component rendering in JournalistResource form by ensuring sections are correctly returned in the mapping.
- Added @var docblocks to resolve lint errors related to auth()->user() and verified query builder return types.
- Standardized file retrieval logic in PartnerResource and improved overall code reliability."
2026-01-12 15:17:21 +07:00

102 lines
3.3 KiB
PHP

<?php
namespace App\Filament\Resources\Visitors;
use App\Filament\Resources\Visitors\Pages\ManageVisitors;
use App\Models\Visitor;
use BackedEnum;
use Filament\Forms\Components\DatePicker;
use Filament\Resources\Resource;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use UnitEnum;
class VisitorResource extends Resource
{
protected static ?string $model = Visitor::class;
protected static string|UnitEnum|null $navigationGroup = 'Monitoring';
protected static string|BackedEnum|null $navigationIcon = Heroicon::ChartBar;
protected static ?string $navigationLabel = 'Pengunjung';
protected static ?int $navigationSort = 4;
protected static ?string $slug = 'monitoring/visitors';
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('date')
->label('Tanggal & Waktu')
->date('l, d F Y')
->sortable(),
TextColumn::make('route')
->label('Halaman')
->searchable()
->sortable(),
TextColumn::make('method')
->label('Method')
->badge()
->color(fn (string $state): string => match ($state) {
'GET' => 'success',
'POST' => 'warning',
default => 'gray',
}),
TextColumn::make('status')
->label('Status')
->badge()
->color(fn (int $state): string => $state >= 200 && $state < 300 ? 'success' : 'danger'),
TextColumn::make('ip')
->label('IP Address')
->searchable(),
TextColumn::make('counter')
->label('Hits')
->numeric()
->sortable(),
TextColumn::make('user.name')
->label('User')
->placeholder('Guest'),
])
->defaultSort('date', 'desc')
->filters([
SelectFilter::make('method')
->options([
'GET' => 'GET',
'POST' => 'POST',
]),
Filter::make('date')
->schema([
DatePicker::make('from')->time()->autocomplete(false),
DatePicker::make('until')->time()->autocomplete(false),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when($data['from'], fn (Builder $q): Builder => $q->whereDate('date', '>=', $data['from']))
->when($data['until'], fn (Builder $q): Builder => $q->whereDate('date', '<=', $data['until']));
}),
])
->recordActions([])
->toolbarActions([]);
}
public static function getPages(): array
{
return [
'index' => ManageVisitors::route('/'),
];
}
}