Table TextInputColumn Update Other Model

hi guys seek help, Is it possible to update data from another model? For example, in this code: php Copy code class ScorecardTableWidget extends BaseWidget { protected $listeners = ['refreshScorecardTable' => '$refresh']; public function table(Table $table): Table { $properties = ScorecardProperty::all(); $columns = [ Tables\Columns\TextColumn::make('name') ->label('Criteria'), Tables\Columns\TextInputColumn::make('weightage'), ]; foreach ($properties as $property) { $columns[] = Tables\Columns\TextInputColumn::make("score_{$property->id}") ->label($property->name) ->beforeStateUpdated(function ($record, $state) use ($property) { ScorecardScore::updateOrCreate( [ 'scorecard_property_id' => $property->id, 'scorecard_criteria_id' => $record->id, ], ['score' => $state] ); $this->dispatch('refreshScorecardTable'); }); } return $table->query(ScorecardCriteria::query()) ->columns($columns); } }
4 Replies
Alvika Aji Prahasta
Alvika Aji PrahastaOPβ€’4mo ago
Note: that's code it's work, score updated, but have some error undifined column score_1, i know that because model ScorecardCriteria does'nt have that column bump
Nuekrato
Nuekratoβ€’4mo ago
That's because Filament thinks that each form input relates to a model property. You are using a custom identifier (TextInputColumn::make("score_{$property->id}")) that does not belong to any model property. This use case is described in the docs: https://filamentphp.com/docs/3.x/forms/advanced#field-dehydration Try to use the TextInputColumn with the ->dehydrated(false) option.
slakkie
slakkieβ€’3mo ago
@Alvika Aji Prahasta me again πŸ™‚ is the listener on your example working and how are you dispatching the event?
Parimal
Parimalβ€’3mo ago
Event can be dispatched from method by
$this->dispatch('refreshScorecardTable')
$this->dispatch('refreshScorecardTable')
Want results from more Discord servers?
Add your server