Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nyi0309's avatar

How can i update Field Information when reactive doenst work

I would like to update the array for the disabledDates() as soon as the item changes. I tried using afterStateUpdated in the select field for Item, but unfortunately it doesn't work. Then I made the field reactive and wrote a small function that outputs the occupied days based on the item. When editing, the correct days are loaded for the item (screenshot 1). But if I change the item or add a new one, no data is loaded? How can I make this reactive?

Select::make('item_id') ->label('Artikel') ->options(Item::query()->pluck('name', 'id')) ->required() ->reactive() ->columnSpan([ 'md' => 5, 'lg' => 2, ]) ->afterStateUpdated(fn ($state, Set $set) => $set('price', Item::find($state)?->price ?? 0)) ->afterStateUpdated(function (Get $get, Set $set, $state) { $set('date_range', null); self::updateTotals($get, $set); }) ->searchable(),

            DateRangePicker::make('date_range')
                ->label('Buchungszeitraum')
                ->required()

                ->autoApply()
                ->columnSpan([
                    'lg' => 3,
                ])
        
            ->disabledDates(function (Get $get) {
                
                $disabledDates = [];

                
                $itemId = $get('item_id');
                if ($itemId) {
                   
                    $bookings = BookingPosition::where('item_id', $itemId)->get();

                  
                    foreach ($bookings as $booking) {
                        $fromDate = \Carbon\Carbon::parse($booking->from_date);
                        $toDate = \Carbon\Carbon::parse($booking->to_date);
                        $period = \Carbon\CarbonPeriod::create($fromDate, $toDate);
                        foreach ($period as $date) {
                            $disabledDates[] = $date->format('Y-m-d');
                        }
                    }
                }
                return $disabledDates;
            })
            ->disabledDates(function (Get $get) {
                
                $disabledDates = [];

                $itemId = $get('item_id');
                if ($itemId) {
                   
                    $bookings = BookingPosition::where('item_id', $itemId)->get();

                    foreach ($bookings as $booking) {
                        $fromDate = \Carbon\Carbon::parse($booking->from_date);
                        $toDate = \Carbon\Carbon::parse($booking->to_date);
                        $period = \Carbon\CarbonPeriod::create($fromDate, $toDate);
                        foreach ($period as $date) {
                            $disabledDates[] = $date->format('Y-m-d');
                        }
                    }
                }
                return $disabledDates;
            })
0 likes
0 replies

Please or to participate in this conversation.