Customization of how your models will be logged is controlled when implementing getActivitylogOptions
. You can start from the defaults and override values as needed.
The most basic example of an Activity logged model would be:
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;
class YourModel extends Model
{
use LogsActivity;
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults();
}
}
This call to LogOptions::defaults()
yields the following default options:
public ?string $logName = null;
public bool $submitEmptyLogs = true;
public bool $logFillable = false;
public bool $logOnlyDirty = false;
public bool $logUnguarded = false;
public array $logAttributes = [];
public array $logExceptAttributes = [];
public array $dontLogIfAttributesChangedOnly = [];
public array $attributeRawValues = [];
public ?Closure $descriptionForEvent = null;
##Options methods
##defaults
public static function defaults(): LogOption;
##logAll
This method is equivalent to ->logOnly(['*'])
.
public function logAll(): LogOption;
##logUnguarded
This option will respect the wildcard *
, ->logAll()
and ->logFillable()
methods.
public function logUnguarded(): LogOption;
##logFillable
This option will respect the wildcard *
, ->logAll()
and ->logUnguarded()
methods.
public function logFillable(): LogOption;
##dontLogFillable
public function dontLogFillable(): LogOption;
##logOnlyDirty
public function logOnlyDirty(): LogOption;
##logOnly
public function logOnly(array $attributes): LogOption;
##logExcept
Convenient method for logOnly()
public function logExcept(array $attributes): LogOption;
##dontLogIfAttributesChangedOnly
public function dontLogIfAttributesChangedOnly(array $attributes): LogOption;
##dontSubmitEmptyLogs
public function dontSubmitEmptyLogs(): LogOption;
##submitEmptyLogs
public function submitEmptyLogs(): LogOption;
##useLogName
public function useLogName(string $logName): LogOption;
##useAttributeRawValues
public function useAttributeRawValues(array $attributes): LogOption;
##setDescriptionForEvent
public function setDescriptionForEvent(Closure $callback): LogOption;