main

filamentphp/demo

Last updated at: 29/12/2023 09:43

Dashboard.php

TLDR

This file is a part of the Demo Projects project and is located at app/Filament/Pages/Dashboard.php. It contains a class called Dashboard which extends a base class BaseDashboard. The class has a method filtersForm() which takes a Form object as a parameter and returns a modified form.

Method filtersForm

This method takes a Form object as a parameter and returns a modified form. Within the method, the form schema is defined using the schema() method of the form object. It contains a single section with three components: a boolean select input for business customers only, a date picker input for the start date, and a date picker input for the end date. The date picker inputs have some logic to set their min and max values based on each other.

Classes

Class Dashboard

This class is a subclass of BaseDashboard and is located in the namespace App\Filament\Pages. It uses a trait called HasFiltersForm from the BaseDashboard namespace. The class has a single method called filtersForm().

<?php

namespace App\Filament\Pages;

use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Pages\Dashboard as BaseDashboard;

class Dashboard extends BaseDashboard
{
    use BaseDashboard\Concerns\HasFiltersForm;

    public function filtersForm(Form $form): Form
    {
        return $form
            ->schema([
                Section::make()
                    ->schema([
                        Select::make('businessCustomersOnly')
                            ->boolean(),
                        DatePicker::make('startDate')
                            ->maxDate(fn (Get $get) => $get('endDate') ?: now()),
                        DatePicker::make('endDate')
                            ->minDate(fn (Get $get) => $get('startDate') ?: now())
                            ->maxDate(now()),
                    ])
                    ->columns(3),
            ]);
    }
}