jackoripo
Possible to use TextInputColumn to update a relationship that has pivot table?
Just as an addition I have added a notification to each TextInputColumn
Tables\Columns\TextInputColumn::make('monday')
->rules(['required', 'numeric', 'between:0,24'])
->updateStateUsing(function (Model $record, $state) {
// Get the old Monday hours and calculate the difference
$oldHours = $record->monday;
$difference = $oldHours - $state;
// Update the 'monday' column and calculate the new contracted hours
$record->monday = $state;
$contractedDifference = $record->contracted_hours - $difference;
// Update the 'contracted_hours' column
$record->contracted_hours = $contractedDifference;
$record->save();
Notification::make()
->title('Updated successfully')
->icon('heroicon-o-face-smile')
->iconColor('success')
->duration(3000)
->send();
// Return the updated model instance
return $record;
}),
9 replies