36 lines
940 B
PHP
36 lines
940 B
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Models\Product;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Widgets\TableWidget;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
class TopProductsWidget extends TableWidget
|
|
{
|
|
protected int | string | array $columnSpan = 'full';
|
|
|
|
protected function getTableHeading(): string
|
|
{
|
|
return '热门产品';
|
|
}
|
|
|
|
protected function getTableQuery(): Builder
|
|
{
|
|
return Product::query()
|
|
->orderByDesc('hot_score')
|
|
->orderByDesc('view_count');
|
|
}
|
|
|
|
protected function getTableColumns(): array
|
|
{
|
|
return [
|
|
TextColumn::make('name')->label('产品')->searchable()->limit(30),
|
|
TextColumn::make('hot_score')->label('热度')->sortable(),
|
|
TextColumn::make('view_count')->label('浏览')->sortable(),
|
|
TextColumn::make('click_count')->label('点击')->sortable(),
|
|
];
|
|
}
|
|
}
|