F
Filament13mo ago
Rozay

mutateRecordDataUsing

Hello, I am working on a system to manage who is on call at a particular time. We have a rota per day, and I want the user to be able to replicate a rota, automatically increasing the day by 1. However, the mutateRecordDataUsing method doesn't seem to be applying my changes. I am calling it from my resource table like so:
Tables\Actions\ReplicateAction::make()
->mutateRecordDataUsing(function (array $data): array {
$data['rota_date'] = now()->addDays(1)->format('Y-m-d');
$data['description'] = 'Rota for '.$data['rota_date']->format('d F Y');
return $data;
})
Tables\Actions\ReplicateAction::make()
->mutateRecordDataUsing(function (array $data): array {
$data['rota_date'] = now()->addDays(1)->format('Y-m-d');
$data['description'] = 'Rota for '.$data['rota_date']->format('d F Y');
return $data;
})
The rota is replicated but with the same date details as the last one. I have experience with PHP/Laravel but I'm new to Livewire and Filament. I am sure I am missing something extremely simple! Any advice would be appreciated.
Solution:
Hello, thanks for your reply. I changed direction on this so the rotas are handled differently now, I did run into a similar issue with another one of my models and ended up using the before method on the replicate action: ```php ->before(function (Grades $record) { $record->name = $record->name . ' (Copy)';...
Jump to solution
2 Replies
Leander_ac
Leander_ac12mo ago
Hey, im having the same issue, did you resolve this by any chance? I found a way around this by using:
->beforeReplicaSaved(function (Application $record) {
$record['examination_id'] = null;
$record->save();
})
->beforeReplicaSaved(function (Application $record) {
$record['examination_id'] = null;
$record->save();
})
Hope this helps!
Solution
Rozay
Rozay12mo ago
Hello, thanks for your reply. I changed direction on this so the rotas are handled differently now, I did run into a similar issue with another one of my models and ended up using the before method on the replicate action:
->before(function (Grades $record) {
$record->name = $record->name . ' (Copy)';
}),
->before(function (Grades $record) {
$record->name = $record->name . ' (Copy)';
}),
Want results from more Discord servers?
Add your server