Filament Multiple Dashboards: Different Widgets for Roles

Filament has a great customizable dashboard. But what if you want to show different things there, for different users, like administrators and simple users? With Filament, it's easy.

In this example, we have User and Task models.

The goal of different dashboards is this:

  • Admins will see cards with numbers like "Total users", "Users Registered Today" and "Tasks Created Today".
  • Non-admins will just see "Tasks Due Today" and some greeting text

Final admin view:

final admin dashboard view

Final non-admin view:

final other users dashboard view

In fact, it won't be multiple dashboards, it will be one dashboard with different widget settings for each role.

For this quick example, the Admin user will be set in the Users table by setting the is_admin field to true.

The Task model will have with only two fields: title and due_date.


Conditionally Hiding Widgets

First, let's make widgets that only the admin user will be able to see.

We need to create a widget with three cards: total users count, users registered today count, and tasks created today count.

php artisan make:filament-widget AdminWidgets --stats-overview

app/Filament/Widgets/AdminWidgets.php:

use App\Models\User;
use App\Models\Task;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Card;
 
class AdminWidgets extends BaseWidget
{
protected function getCards(): array
{
return [
Card::make('Total Users', User::count()),
Card::make('Users Registered Today', User::whereDate('created_at', today())->count()),
Card::make('Tasks Created Today', Task::whereDate('created_at', today())->count()),
];
}
}

After visiting the Dashboard page, you will see three cards.

But if you visit Dashboard with the non-admin user, you would also see those cards. To tell widgets who can see them, we just need to use the canView() method.

admin widgets dashboard

app/Filament/Widgets/AdminWidgets.php:

class AdminWidgets extends BaseWidget
{
protected static ?int $sort = 2;
 
protected function getCards(): array
{
return [
Card::make('Total Users', User::count()),
Card::make('Users Registered Today', User::whereDate('created_at', today())->count()),
Card::make('Tasks Created Today', Task::whereDate('created_at', today())->count()),
];
}
 
public static function canView(): bool
{
return auth()->user()->is_admin;
}
}

Now only users with is_admin set to true will see this widget.

non-admin users cannot see widget

Let's create another widget that will show users' Tasks due today.

php artisan make:filament-widget TasksDueToday --stats-overview

app/Filament/Widgets/TasksDueToday.php:

class TasksDueToday extends BaseWidget
{
protected function getCards(): array
{
return [
Card::make('Tasks Due Today', auth()->user()->tasks()->whereDate('due_date', today())->count()),
];
}
}

By default, everyone can see widgets, so we don't need to do anything extra.

widgets for all users


Custom Dashboard

If you would like to customize the dashboard, you need to create a new file at app/Filament/Pages/Dashboard.php which needs to extend the original dashboard.

app/Filament/Pages/Dashboard.php:

use Filament\Pages\Dashboard as BasePage;
 
class Dashboard extends BasePage
{
// ...
}

And remove the original Dashboard class from the configuration file.

config/filament.php:

'pages' => [
// ...
'register' => [],
],

Now, because Dashboard is just a Filament Page, you can add everything that page can have. For example, let's add a subheading that will only be shown if the user isn't an admin.

app/Filament/Pages/Dashboard.php:

use Illuminate\Contracts\Support\Htmlable;
use Filament\Pages\Dashboard as BasePage;
 
class Dashboard extends BasePage
{
protected function getSubheading(): string | Htmlable | null
{
if (auth()->user()->is_admin) {
return null;
}
 
return 'Here you will see an overview of your tasks.';
}
}

dashboard sub heading text


And that's it, here's how to customize Filament dashboard by user roles.

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 42 courses (796 lessons, total 45 h 33 min)
  • 49 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent Premium Tutorials