Text Input Column Update hasMany relation column

basically i viewing data forecast_items using filament table builder

i have a model ForecastItem, inside forecast_items table has many values

ForecastItem.php

 public function forecastValues(): HasMany
{
      return $this->hasMany(ForecastValue::class);
}


ForecastValue.php

 public function item(): BelongsTo
{
      return $this->belongsTo(ForecastItem::class);
}


how can i get value state like this

TextInputColumn::make('forecastValues.am_amount')


for now i wrote like below. but when stateUpdated it's say am_amount column not found in forecast_items ( i know column am_amount is from the forecast_values table not from forecast_items)

TextInputColumn::make('am_amount')
                        ->label('AM')
                        ->getStateUsing(function (Model $record) {
                            return $record->forecastValues()->where('day', 'sunday')->first()?->am_amount;
                        })->beforeStateUpdated(function ($record, $state) {
                            $value = $record->forecastValues()->where('day', 'sunday')->first();
                            $value->am_amount = $state;
                            $value->save();
                        })


Any idea? here's the database design
image.png
Was this page helpful?