F
Filament9mo ago
Noor

Old status update To New status

There is a form in which I have a status field and I want it to be saved and update in database for update my code is
protected function mutateFormDataBeforeSave(array $data): array
{

$dbStatus = $this->record->fresh()->status_id;

if ($dbStatus !== $data['status_id']) {
$data['status_update'] = now();
}
return $data;
}
protected function mutateFormDataBeforeSave(array $data): array
{

$dbStatus = $this->record->fresh()->status_id;

if ($dbStatus !== $data['status_id']) {
$data['status_update'] = now();
}
return $data;
}
But when I run it it keep changing my form updated_at which I dont want. I just want status_update to be changed when user change it.
10 Replies
mvenghaus
mvenghaus9mo ago
if you use the default timestamps from laravel then this is always the case .. you have to modify your model
mvenghaus
mvenghaus9mo ago
How to disable model timestamps in Laravel?
laravel timestamp false, laravel timestamps disable, laravel disable timestamps, laravel model timestamps false, laravel eloquent timestamps false
Noor
NoorOP9mo ago
@mvenghaus but then it would not change updated_at which I want to change but not when I change status type my point is if user change status it should give update .. it should not affect updated_at .... update_at would only get affectecd or change when user change something else on the form
awcodes
awcodes9mo ago
If they change the status though the record is getting updated which is why updated_at is getting changed. It’s kind of the entire point of the updated_at field.
mvenghaus
mvenghaus9mo ago
you could also update without the model, db query
Noor
NoorOP9mo ago
Yes , I know updated_at is like for full form if user change its gonna update, but I want status_update seperatly which only will update when user change just status nothing else And when status_update is gonna update I dont want update_at to be update @awcodes
awcodes
awcodes9mo ago
Then you’ll probably need an observer to get the old value and reset it with the old value during saving. Still doesn’t make sense because the record is changing is the status changes, but it’s your app. 😀
Noor
NoorOP9mo ago
something like this ?
public function updated(Lead $leads): void
{
if($leads->isDirty('status_id')) {
$leads->status_update = now();
}
}
public function updated(Lead $leads): void
{
if($leads->isDirty('status_id')) {
$leads->status_update = now();
}
}
awcodes
awcodes9mo ago
Yea. But my point was getting the old value for updated_at and manually setting it as part of the form data so it gets “updated” with the old value instead of getting set to the current time.
Noor
NoorOP9mo ago
sorry did not catch ya
Want results from more Discord servers?
Add your server