DEV Community

Rupadana
Rupadana

Posted on

Create Stats overview widgets

Introduction

Filament comes with a "stats overview" widget template, which you can use to display a number of different stats in a single widget, without needing to write a custom view.

Start by creating a widget with the command:

php artisan make:filament-widget StatsOverview --stats-overview
Enter fullscreen mode Exit fullscreen mode

Then return Stat instances from the getStats() method:

<?php

namespace App\Filament\Widgets;

use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;

class StatsOverview extends BaseWidget
{
    protected function getStats(): array
    {
        return [
            Stat::make('Unique views', '192.1k'),
            Stat::make('Bounce rate', '21%'),
            Stat::make('Average time on page', '3:12'),
        ];
    }
}
Enter fullscreen mode Exit fullscreen mode

Now, check out your widget in the dashboard.

Top comments (1)

Collapse
 
rupadana profile image
Rupadana

Hi, kindly leave a like and comment if you got new insight! 🔥