Count when click on table row to view model

Hey! I have a resource table with messages and a simple view modal. How i can set the reat_at date on the model when the message modal was opened?
5 Replies
awcodes
awcodes2y ago
Why do you need to set the created_at date when the modal is opened as opposed to letting the db set it when the record is created? Assuming reat_at is a typo. Not sure.
DivDax
DivDaxOP2y ago
Hey awcodes. My Message model has the columns read_at (nullable), created_at, updated_at. i want to update the read_at when the view modal was opened. Do you know any hooks, or anything else where i can do a: $model->read_at = now(); $model->save(); ?
awcodes
awcodes2y ago
Hm.. that’s difficult since a view isn’t a form and doesn’t have a form. You might need a custom action that can emit an event and a listener to update the record. Assuming you need to save it somewhere. But if you aren’t persisting it then it shouldn’t matter.
DivDax
DivDaxOP2y ago
I found a method i can use on the ViewAction class like this:
Tables\Actions\ViewAction::make()
->mutateRecordDataUsing(function(Email $record) {
$record->read_at = now();
$record->save();
return $record->toArray();
}),
Tables\Actions\ViewAction::make()
->mutateRecordDataUsing(function(Email $record) {
$record->read_at = now();
$record->save();
return $record->toArray();
}),
🥳 Problem solved. 🙂 Thank you for your time awcodes.
awcodes
awcodes2y ago
Glad you figured it out.
Want results from more Discord servers?
Add your server