> ## Documentation Index
> Fetch the complete documentation index at: https://filament-34a8cf01.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Widgets

> [!WARNING]
>
> You are currently viewing the documentation for Filament 3.x, which is a previous version of Filament.
>
> Looking for the current stable version? Visit the [5.x documentation](https://filament-34a8cf01.mintlify.site/5.x).

## Overview

![Filament](https://filament-34a8cf01.mintlify.site/docs/images/laracasts/filament-laracasts-logo.webp)
![Laracasts](https://filament-34a8cf01.mintlify.site/docs/images/laracasts/laracasts.svg)

### Widgets

Watch the Rapid Laravel Development with Filament series on Laracasts - it will teach you the basics of adding widgets to Filament resources.

[Play Video](https://laracasts.com/series/rapid-laravel-development-with-filament/episodes/15?referer=DanHarrin)

![Laracasts](https://filament-34a8cf01.mintlify.site/docs/images/laracasts/laracasts.svg)

![Kevin McKee](https://avatars.githubusercontent.com/u/4503765?v=4)

Kevin McKee

Instructor

[https://twitter.com/iAmKevinMcKee](https://twitter.com/iAmKevinMcKee)

[https://kevinmckee.me](https://kevinmckee.me)

[https://github.com/iAmKevinMcKee](https://github.com/iAmKevinMcKee)

Filament allows you to display widgets inside pages, below the header and above the footer.

You can use an existing [dashboard widget](https://filament-34a8cf01.mintlify.site/3.x/panels/dashboard.md), or create one specifically for the resource.

## Creating a resource widget

To get started building a resource widget:

```bash theme={"theme":"gruvbox-dark-hard"}
php artisan make:filament-widget CustomerOverview --resource=CustomerResource
```

This command will create two files - a widget class in the `app/Filament/Resources/CustomerResource/Widgets` directory, and a view in the `resources/views/filament/resources/customer-resource/widgets` directory.

You must register the new widget in your resource's `getWidgets()` method:

```php theme={"theme":"gruvbox-dark-hard"}
public static function getWidgets(): array
{
    return [
        CustomerResource\Widgets\CustomerOverview::class,
    ];
}
```

If you'd like to learn how to build and customize widgets, check out the [Dashboard](https://filament-34a8cf01.mintlify.site/3.x/panels/dashboard.md) documentation section.

## Displaying a widget on a resource page

To display a widget on a resource page, use the `getHeaderWidgets()` or `getFooterWidgets()` methods for that page:

```php theme={"theme":"gruvbox-dark-hard"}
<?php

namespace App\Filament\Resources\CustomerResource\Pages;

use App\Filament\Resources\CustomerResource;

class ListCustomers extends ListRecords
{
    public static string $resource = CustomerResource::class;

    protected function getHeaderWidgets(): array
    {
        return [
            CustomerResource\Widgets\CustomerOverview::class,
        ];
    }
}
```

`getHeaderWidgets()` returns an array of widgets to display above the page content, whereas `getFooterWidgets()` are displayed below.

If you'd like to customize the number of grid columns used to arrange widgets, check out the [Pages documentation](https://filament-34a8cf01.mintlify.site/3.x/panels/pages.md#customizing-the-widgets-grid).

## Accessing the current record in the widget

If you're using a widget on an [Edit](https://filament-34a8cf01.mintlify.site/3.x/panels/resources/editing-records.md) or [View](https://filament-34a8cf01.mintlify.site/3.x/panels/resources/viewing-records.md) page, you may access the current record by defining a `$record` property on the widget class:

```php theme={"theme":"gruvbox-dark-hard"}
use Illuminate\Database\Eloquent\Model;

public ?Model $record = null;
```

## Accessing page table data in the widget

If you're using a widget on a [List](https://filament-34a8cf01.mintlify.site/3.x/panels/resources/listing-records.md) page, you may access the table data by first adding the `ExposesTableToWidgets` trait to the page class:

```php theme={"theme":"gruvbox-dark-hard"}
use Filament\Pages\Concerns\ExposesTableToWidgets;
use Filament\Resources\Pages\ListRecords;

class ListProducts extends ListRecords
{
    use ExposesTableToWidgets;

    // ...
}
```

Now, on the widget class, you must add the `InteractsWithPageTable` trait, and return the name of the page class from the `getTablePage()` method:

```php theme={"theme":"gruvbox-dark-hard"}
use App\Filament\Resources\ProductResource\Pages\ListProducts;
use Filament\Widgets\Concerns\InteractsWithPageTable;
use Filament\Widgets\Widget;

class ProductStats extends Widget
{
    use InteractsWithPageTable;

    protected function getTablePage(): string
    {
        return ListProducts::class;
    }

    // ...
}
```

In the widget class, you can now access the Eloquent query builder instance for the table data using the `$this->getPageTableQuery()` method:

```php theme={"theme":"gruvbox-dark-hard"}
use Filament\Widgets\StatsOverviewWidget\Stat;

Stat::make('Total Products', $this->getPageTableQuery()->count()),
```

Alternatively, you can access a collection of the records on the current page using the `$this->getPageTableRecords()` method:

```php theme={"theme":"gruvbox-dark-hard"}
use Filament\Widgets\StatsOverviewWidget\Stat;

Stat::make('Total Products', $this->getPageTableRecords()->count()),
```

## Passing properties to widgets on resource pages

When registering a widget on a resource page, you can use the `make()` method to pass an array of [Livewire properties](https://livewire.laravel.com/docs/properties) to it:

```php theme={"theme":"gruvbox-dark-hard"}
protected function getHeaderWidgets(): array
{
    return [
        CustomerResource\Widgets\CustomerOverview::make([
            'status' => 'active',
        ]),
    ];
}
```

This array of properties gets mapped to [public Livewire properties](https://livewire.laravel.com/docs/properties) on the widget class:

```php theme={"theme":"gruvbox-dark-hard"}
use Filament\Widgets\Widget;

class CustomerOverview extends Widget
{
    public string $status;

    // ...
}
```

Now, you can access the `status` in the widget class using `$this->status`.

[Edit this page on GitHub](https://github.com/filamentphp/filament/edit/3.x/packages/panels/docs/03-resources/09-widgets.md)

## Sponsored by

[Your logo here](https://github.com/sponsors/danharrin)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.