get('option')) { case '365': $total = User::query()->whereDate('created_at', '>=', Carbon::now()->addYears(-1)->toDateString())->count(); break; case '30': $total = User::query()->whereDate('created_at', '>=', Carbon::now()->addDays(-30)->toDateString())->count(); break; case '14': $total = User::query()->whereDate('created_at', '>=', Carbon::now()->addDays(-14)->toDateString())->count(); break; case '7': $total = User::query()->whereDate('created_at', '>=', Carbon::now()->addDays(-7)->toDateString())->count(); break; case '3': default: $total = User::query()->whereDate('created_at', '>=', Carbon::now()->addDays(-1)->toDateString())->count(); break; } $this->content($total); $this->total(User::count()); } /** * @param int $percent * * @return $this */ public function total($percent) { return $this->footer( "共 {$percent} 用户" ); } /** * 设置卡片底部内容. * * @param string|Renderable|\Closure $footer * * @return $this */ public function footer($footer) { $this->footer = $footer; return $this; } /** * 渲染卡片内容. * * @return string */ public function renderContent() { $content = parent::renderContent(); return <<

{$content}

{$this->renderFooter()}
HTML; } /** * 渲染卡片底部内容. * * @return string */ public function renderFooter() { return $this->toString($this->footer); } /** * 初始化卡片. */ protected function init() { parent::init(); $this->title('用户数'); $this->dropdown([ '3' => '近三天', '7' => '近一周', '14' => '近两周', '30' => '近一月', '365' => '近一年', ]); } }