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);
}
public function forecastValues(): HasMany
{
return $this->hasMany(ForecastValue::class);
}
ForecastValue.php
public function item(): BelongsTo
{
return $this->belongsTo(ForecastItem::class);
}
public function item(): BelongsTo
{
return $this->belongsTo(ForecastItem::class);
}
how can i get value state like this
TextInputColumn::make('forecastValues.am_amount')
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();
})
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
No description
1 Reply
ahmadrivaldi_arv
ahmadrivaldi_arvOP6mo ago
here's the table... marked red one is from
forecast_items
forecast_items
table and the blue one from
forecast_values
forecast_values
table
No description
Want results from more Discord servers?
Add your server