0

I'm working on a small project using Filamentphp. My form has DatePicker and I'm unable to disable all Weekends days for previous or future years.

It only works for the current year. I couldn't figure out how to use reactive() function on year change. If someone can help me will be grateful that should solve my problem.

public static function weekend($state, $week_days)
        : array
        {
            $dateDay   = ($state === null)
                ? \Carbon\Carbon::now()
                : Carbon::parse($state);
            $year      = $dateDay->year;
            $next_year = $year + 1;
            $month     = $dateDay->month;
            $days      = $dateDay->daysInMonth;

            $arr = [];
            foreach ($week_days as $week_day)
            {
                $days = new \DatePeriod(
                    Carbon::parse("first $week_day of $year"),
                    CarbonInterval::week(),
                    Carbon::parse("last $week_day of january $next_year")
                );
                foreach ($days as $day)
                {
                    array_push($arr, Carbon::parse($day)->format('Y-m-d'));
                }
            }

            return $arr;
        }


 DatePicker::make('issue_start_date')->dispatchEvent('weekend')
                              ->required()
                              ->reactive()
                              ->closeOnDateSelection()
                              ->weekStartsOnSunday()
                              ->afterStateUpdated(function (callable $set, $state)
                              {
                                  $month = date('M', strtotime($state));
                                  $year  = date('Y', strtotime($state));
                                  ($month == null || $year === null)
                                      ? $set('name', null)
                                      : $set('name', $month . ' ' . $year);
                              })
                              ->dehydrateStateUsing(function (callable $set, $state)
                              {
                                  if ($state === null) $set('name', null);
                              })
                              ->disabledDates(fn($state) => self::weekend(state: $state, week_days: ['saturday', 'friday'])), 
Amir Hussain
  • 47
  • 1
  • 8

0 Answers0