FilamentF
Filament2y ago
Eth

issue with updating the price after picking a date

I’m trying to fetch the price from Seasonal json file ($Seasonal) after picking the date update the total price but it doesn’t work, not sure if the issue with my way of fetching the price or the summing it
Forms\Components\DatePicker::make('Date')
                ->required()
                ->live()
                ->dehydrated()
                ->minDate(now())
                ->afterStateUpdated(function ($state, callable $set, callable $get){
                    $place = Place::find($get('placeName'));
                    $Seasonal = $place->Seasonal;
                    $From = collect($Seasonal)->pluck('From');
                    $Until = collect($Seasonal)->pluck('Until');
                    $Price = collect($Seasonal)->pluck('Price');
                    $placePrice = Place::find($get('placePrice'));
                    $reservations = Reservation::where(function ($query) use ($Seasonal, $placePrice, $Price) {
                        foreach ($Seasonal as $season) {
                            $reservations = Place::where(function ($query) use ($season) {
                                $query->where('Seasonal', '>=', $season['From'])
                                    ->where('Seasonal', '<=', $season['Until']);
                            })->get();
                        }
                        if ($placePrice) {
                            $placePrice += $Price->sum();
                        }
                    });
                }),

(Side note: I get the default total price from choosing a name previously, not sure if this could cause an issue)
Was this page helpful?