FilamentF
Filament6mo ago
Lavinx

DatePicker only monday

Is there a way to only enable mondays in the calender? I know you can specify dates that should be disabled, but I would like to only allow users to select mondays without too much hazzle. Is there a functionality to do this?
Solution
A hacky way;

                DatePicker::make('start')
                    ->displayFormat('d-m-Y')
                    ->native(false)
                    ->minDate(now())
                    ->disabledDates(fn () =>
                        collect(CarbonPeriod::create(today(), today()->addDays(31)))
                            ->filter(fn (Carbon $date) => $date->dayOfWeek !== Carbon::MONDAY)
                            ->map(fn (Carbon $date) => $date->format('Y-m-d'))
                            ->values()
                            ->toArray()
                    )
                    ->maxDate(now()->addDays(31))
                    ->closeOnDateSelection(),
Was this page helpful?