F
Filament16mo ago
Mikazor

How to `->getOriginal()` from Model in `afterSave()` hook?

I need the original state of the model and I don't want to use observers
6 Replies
Patrick Boivin
Patrick Boivin16mo ago
Just out of curiosity - what do you need the original state for? Maybe you could grab some of this original data in the beforeSave() hook.
Mikazor
MikazorOP16mo ago
Yes, it's work in beforeSave
protected function beforeSave(): void
{
$this->originalRecord = clone $this->getRecord();
}
protected function beforeSave(): void
{
$this->originalRecord = clone $this->getRecord();
}
I need to create an action log and as I said, I don't want to use observers
awcodes
awcodes16mo ago
Any particular reason for not using observers? It’s kinda what they were designed for. You’d also loose the functionality should you ever use something other than Filament.
Mikazor
MikazorOP16mo ago
Yes. Observers do not work with mass updates. I need to create an event and a listener to handle mass updates, so my logging logic must be in different places. It's not convenient that's why I want to control my logging action from "controllers". Also, it's useful with filament actions that not change model
awcodes
awcodes16mo ago
Fair enough. Was just curious. Thank you for the response.
cheesegrits
cheesegrits16mo ago
In afterSave(), $this->oldFormState should contain all the state paths which have been changed.
No description

Did you find this page helpful?