Replies: 1 comment
-
Hi there, Any feedback? EDIT: I wrote an abstract class that exposes two new methods: use Spatie\LaravelSettings\Settings;
abstract class BaseSettings extends Settings
{
private array $changes = [];
public function __set($name, $value)
{
if (isset($this->{$name}) && $value !== $this->{$name}) {
$this->changes[$name] = $this->{$name};
}
parent::__set($name, $value);
}
public function refresh(): Settings
{
$this->changes = [];
return parent::refresh();
}
public function wasChanged($name): bool
{
return isset($this->changes[$name]) && $this->changes[$name] !== $this->{$name};
}
public function getOriginalValue(string $name)
{
return $this->changes[$name] ?? null;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
It seems that it's not possible to detect which properties changed in order to run some actions. I was looking for something like Laravel's Model
wasChanged
method.Use case:
I have a listener waiting for the
SettingsSaved
event. There are some actions that should run only when some specific properties change. However I'm not able to detect what changed so I'm forced to execute all actions over and over.To me, it would be nice, for example, to be able to detect whether the property
current_configuration
has changed in order to dispatch a job.Waiting for a reply, thanks for your efforts.
Beta Was this translation helpful? Give feedback.
All reactions