完善功能
This commit is contained in:
35
web10/app/Filament/Widgets/TopProductsWidget.php
Normal file
35
web10/app/Filament/Widgets/TopProductsWidget.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user