'array']; } /** * @return MorphTo */ public function revisionable(): MorphTo { return $this->morphTo(); } /** * @return BelongsTo */ public function user(): BelongsTo { return $this->belongsTo(User::class); } public function author(): string { // The live name when the account is at hand — people rename // themselves — and the recorded one otherwise, including once the // account is gone. Never a lazy load: this is read inside table rows. if ($this->relationLoaded('user') && $this->user !== null) { return $this->user->name; } return $this->user_name ?? __('panel.revisions.system'); } /** * The attributes this revision touched. * * @return array */ public function fields(): array { return array_keys($this->changeset ?? []); } /** * What a given attribute looked like before and after. * * @return array{old: mixed, new: mixed} */ public function diff(string $field): array { return [ 'old' => $this->changeset[$field]['old'] ?? null, 'new' => $this->changeset[$field]['new'] ?? null, ]; } /** * The values needed to put a record back the way it was. * * @return array */ public function previousValues(): array { return collect($this->changeset ?? []) ->map(fn (array $change) => $change['old'] ?? null) ->all(); } }