Upgrading to v4 #1078
Unanswered
tontonsb
asked this question in
Show and tell
Upgrading to v4
#1078
Replies: 1 comment
-
More complete solution would look like, <?php
namespace App\Abstracts;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
trait ActivityLogTrait
{
use LogsActivity;
public function getActivityLogOptions(): LogOptions
{
$logOption = LogOptions::defaults();
if (isset($this->logAttributes)) {
$logOption->logOnly($this->logAttributes);
}
if (isset($this->logOnlyDirty)) {
$logOption->logOnlyDirty();
}
if (isset($this->submitEmptyLogs)) {
$logOption->dontSubmitEmptyLogs();
}
if (method_exists($this, 'getDescriptionForEvent')) {
$logOption->setDescriptionForEvent(fn(string $eventName) => $this->getDescriptionForEvent($eventName));
}
if (isset($this->logName)) {
$logOption->useLogName($this->logName);
}
if (isset($this->ignoreChangedAttributes)) {
$logOption->dontLogIfAttributesChangedOnly($this->ignoreChangedAttributes);
}
return $logOption;
}
} |
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
-
Recently I've been updating a couple of projects to v4. I ended up creating a small trait that can be made once per project and adds fairly good backwards compatibility.
Of course, this is project specific, but the general idea is to make something with appropriate defaults and taking settings from the model properties as before:
And replace the
use LogsActivity;
withuse Log;
in the models.I know v4 is not a new thing, but maybe someone comes across a need for this :)
Beta Was this translation helpful? Give feedback.
All reactions