© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
1 reply
ahmadrivaldi_arv

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
image.png
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

text input with relation
FilamentFFilament / ❓┊help
2y ago
Text Input Column Notification
FilamentFFilament / ❓┊help
3y ago
Select field hasMany relation
FilamentFFilament / ❓┊help
3y ago