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
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
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.@Alvika Aji Prahasta me again π is the listener on your example working and how are you dispatching the event?
Event can be dispatched from method by