1 | <?php |
||
8 | trait DetectsChanges |
||
9 | { |
||
10 | protected $oldAttributes = []; |
||
11 | |||
12 | protected static function bootDetectsChanges() |
||
25 | |||
26 | public function attributesToBeLogged(): array |
||
27 | { |
||
28 | $attributes = []; |
||
29 | |||
30 | if (isset(static::$logFillable) && static::$logFillable) { |
||
31 | $attributes = array_merge($attributes, $this->fillable); |
||
|
|||
32 | } |
||
33 | |||
34 | if (isset(static::$logAttributes) && is_array(static::$logAttributes)) { |
||
35 | if (in_array('*', static::$logAttributes)) { |
||
36 | $withoutWildcard = array_diff(static::$logAttributes, ['*']); |
||
37 | |||
38 | $attributes = array_merge($attributes, array_keys($this->attributes), $withoutWildcard); |
||
39 | } else { |
||
40 | $attributes = array_merge($attributes, static::$logAttributes); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | return $attributes; |
||
45 | } |
||
46 | |||
47 | public function shouldlogOnlyDirty(): bool |
||
55 | |||
56 | public function attributeValuesToBeLogged(string $processingEvent): array |
||
89 | |||
90 | public static function logChanges(Model $model): array |
||
103 | |||
104 | protected static function getRelatedModelAttributeValue(Model $model, string $attribute): array |
||
116 | } |
||
117 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: