--- title: Pages --- ## Overview Filament allows you to create completely custom pages for the app. ## Creating a page To create a new page, you can use: ```bash php artisan make:filament-page Settings ``` This command will create two files - a page class in the `/Pages` directory of the Filament directory, and a view in the `/pages` directory of the Filament views directory. Page classes are all full-page [Livewire](https://livewire.laravel.com) components with a few extra utilities you can use with the panel. ## Conditionally hiding pages in navigation You can prevent pages from appearing in the menu by overriding the `shouldRegisterNavigation()` method in your Page class. This is useful if you want to control which users can see the page in the sidebar. ```php public static function shouldRegisterNavigation(): bool { return auth()->user()->canManageSettings(); } ``` Please be aware that all users will still be able to visit this page through its direct URL, so to fully limit access, you must also check in the `mount()` method of the page: ```php public function mount(): void { abort_unless(auth()->user()->canManageSettings(), 403); } ``` ## Adding actions to pages Actions are buttons that can perform tasks on the page, or visit a URL. You can read more about their capabilities [here](../actions). Since all pages are Livewire components, you can [add actions](../actions/adding-an-action-to-a-livewire-component#adding-the-action) anywhere. Pages already have the `InteractsWithActions` trait, `HasActions` interface, and `` Blade component all set up for you. ### Header actions You can also easily add actions to the header of any page, including [resource pages](resources/getting-started). You don't need to worry about adding anything to the Blade, we handle that for you. Just return your actions from the `getHeaderActions()` method of the page class: ```php use Filament\Actions\Action; protected function getHeaderActions(): array { return [ Action::make('edit') ->url(route('posts.edit', ['post' => $this->post])), Action::make('delete') ->requiresConfirmation() ->action(fn () => $this->post->delete()), ]; } ``` ### Refreshing form data If you're using actions on an [Edit](resources/editing-records) or [View](resources/viewing-records) resource page, you can refresh data within the main form using the `refreshFormData()` method: ```php use App\Models\Post; use Filament\Actions\Action; Action::make('approve') ->action(function (Post $record) { $record->approve(); $this->refreshFormData([ 'status', ]); }) ``` This method accepts an array of model attributes that you wish to refresh in the form. ## Adding widgets to pages Filament allows you to display [widgets](dashboard) inside pages, below the header and above the footer. To add a widget to a page, use the `getHeaderWidgets()` or `getFooterWidgets()` methods: ```php use App\Filament\Widgets\StatsOverviewWidget; protected function getHeaderWidgets(): array { return [ StatsOverviewWidget::class ]; } ``` `getHeaderWidgets()` returns an array of widgets to display above the page content, whereas `getFooterWidgets()` are displayed below. If you'd like to learn how to build and customize widgets, check out the [Dashboard](dashboard) documentation section. ### Customizing the widgets' grid You may change how many grid columns are used to display widgets. You may override the `getHeaderWidgetsColumns()` or `getFooterWidgetsColumns()` methods to return a number of grid columns to use: ```php protected function getHeaderWidgetsColumns(): int | array { return 3; } ``` #### Responsive widgets grid You may wish to change the number of widget grid columns based on the responsive [breakpoint](https://tailwindcss.com/docs/responsive-design#overview) of the browser. You can do this using an array that contains the number of columns that should be used at each breakpoint: ```php protected function getHeaderWidgetsColumns(): int | array { return [ 'md' => 4, 'xl' => 5, ]; } ``` This pairs well with [responsive widget widths](dashboard#responsive-widget-widths). #### Passing data to widgets from the page You may pass data to widgets from the page using the `getWidgetsData()` method: ```php protected function getWidgetsData(): array { return [ 'stats' => [ 'total' => 100, ], ]; } ``` Now, you can define a corresponding public `$stats` array property on the widget class, which will be automatically filled: ```php public $stats = []; ``` ### Passing properties to widgets on pages When registering a widget on a page, you can use the `make()` method to pass an array of [Livewire properties](https://livewire.laravel.com/docs/properties) to it: ```php use App\Filament\Widgets\StatsOverviewWidget; protected function getHeaderWidgets(): array { return [ StatsOverviewWidget::make([ 'status' => 'active', ]), ]; } ``` This array of properties gets mapped to [public Livewire properties](https://livewire.laravel.com/docs/properties) on the widget class: ```php use Filament\Widgets\Widget; class StatsOverviewWidget extends Widget { public string $status; // ... } ``` Now, you can access the `status` in the widget class using `$this->status`. ## Customizing the page title By default, Filament will automatically generate a title for your page based on its name. You may override this by defining a `$title` property on your page class: ```php protected static ?string $title = 'Custom Page Title'; ``` Alternatively, you may return a string from the `getTitle()` method: ```php use Illuminate\Contracts\Support\Htmlable; public function getTitle(): string | Htmlable { return __('Custom Page Title'); } ``` ## Customizing the page navigation label By default, Filament will use the page's [title](#customizing-the-page-title) as its [navigation](navigation) item label. You may override this by defining a `$navigationLabel` property on your page class: ```php protected static ?string $navigationLabel = 'Custom Navigation Label'; ``` Alternatively, you may return a string from the `getNavigationLabel()` method: ```php public static function getNavigationLabel(): string { return __('Custom Navigation Label'); } ``` ## Customizing the page URL By default, Filament will automatically generate a URL (slug) for your page based on its name. You may override this by defining a `$slug` property on your page class: ```php protected static ?string $slug = 'custom-url-slug'; ``` ## Customizing the page heading By default, Filament will use the page's [title](#customizing-the-page-title) as its heading. You may override this by defining a `$heading` property on your page class: ```php protected ?string $heading = 'Custom Page Heading'; ``` Alternatively, you may return a string from the `getHeading()` method: ```php public function getHeading(): string { return __('Custom Page Heading'); } ``` ### Adding a page subheading You may also add a subheading to your page by defining a `$subheading` property on your page class: ```php protected ?string $subheading = 'Custom Page Subheading'; ``` Alternatively, you may return a string from the `getSubheading()` method: ```php public function getSubheading(): ?string { return __('Custom Page Subheading'); } ``` ## Replacing the page header with a custom view You may replace the default [heading](#customizing-the-page-heading), [subheading](#adding-a-page-subheading) and [actions](#header-actions) with a custom header view for any page. You may return it from the `getHeader()` method: ```php use Illuminate\Contracts\View\View; public function getHeader(): ?View { return view('filament.settings.custom-header'); } ``` This example assumes you have a Blade view at `resources/views/filament/settings/custom-header.blade.php`. ## Rendering a custom view in the footer of the page You may also add a footer to any page, below its content. You may return it from the `getFooter()` method: ```php use Illuminate\Contracts\View\View; public function getFooter(): ?View { return view('filament.settings.custom-footer'); } ``` This example assumes you have a Blade view at `resources/views/filament/settings/custom-footer.blade.php`. ## Customizing the maximum content width By default, Filament will restrict the width of the content on the page, so it doesn't become too wide on large screens. To change this, you may override the `getMaxContentWidth()` method. Options correspond to [Tailwind's max-width scale](https://tailwindcss.com/docs/max-width). The options are `xs`, `sm`, `md`, `lg`, `xl`, `2xl`, `3xl`, `4xl`, `5xl`, `6xl`, `7xl`, `prose`, `screen-sm`, `screen-md`, `screen-lg`, `screen-xl`, `screen-2xl` and `full`. The default is `7xl`: ```php public function getMaxContentWidth(): ?string { return 'full'; } ```