Skip to main content

Introduction

Filament allows you to display widgets inside pages, below the header and above the footer. You can use an existing dashboard widget, or create one specifically for the resource.

Creating a resource widget

To get started building a resource widget:
This command will create two files - a widget class in the app/Filament/Resources/Customers/Widgets directory, and a view in the resources/views/filament/resources/customers/widgets directory. You must register the new widget in your resource’s getWidgets() method:
If you’d like to learn how to build and customize widgets, check out the Dashboard 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:
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.

Accessing the current record in the widget

If you’re using a widget on an Edit or View page, you may access the current record by defining a $record property on the widget class:

Accessing page table data in the widget

If you’re using a widget on a List page, you may access the table data by first adding the ExposesTableToWidgets trait to the page class:
Now, on the widget class, you must add the InteractsWithPageTable trait, and return the name of the page class from the getTablePage() method:
In the widget class, you can now access the Eloquent query builder instance for the table data using the $this->getPageTableQuery() method:
Alternatively, you can access a collection of the records on the current page using the $this->getPageTableRecords() method:

Accessing the total table records count

If you need the total count of all records for the table query without executing an additional count query, you can use the $tableRecordsCount property:

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 to it:
This array of properties gets mapped to public Livewire properties on the widget class:
Now, you can access the status in the widget class using $this->status.