2022-06-27 01:39:01 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
|
|
|
|
|
|
use App\Models\Torrent;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use Filament\Widgets\LineChartWidget;
|
|
|
|
|
use Flowframe\Trend\Trend;
|
|
|
|
|
use Flowframe\Trend\TrendValue;
|
|
|
|
|
|
|
|
|
|
class UserTrend extends LineChartWidget
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
protected static ?int $sort = 3;
|
|
|
|
|
|
2022-06-27 13:22:16 +08:00
|
|
|
protected static ?string $pollingInterval = null;
|
|
|
|
|
|
2022-06-27 01:39:01 +08:00
|
|
|
protected function getHeading(): ?string
|
|
|
|
|
{
|
|
|
|
|
return __('dashboard.user_trend.page_title');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getData(): array
|
|
|
|
|
{
|
|
|
|
|
$data = Trend::model(User::class)
|
|
|
|
|
->dateColumn('added')
|
|
|
|
|
->between(
|
|
|
|
|
start: now()->subDays(30),
|
|
|
|
|
end: now(),
|
|
|
|
|
)
|
|
|
|
|
->perDay()
|
|
|
|
|
->count();
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'datasets' => [
|
|
|
|
|
[
|
2022-07-04 14:41:27 +08:00
|
|
|
'label' => __('label.user.label'),
|
2022-06-27 01:39:01 +08:00
|
|
|
'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'labels' => $data->map(fn (TrendValue $value) => Carbon::parse($value->date)->format('m-d')),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|