*/ public function toArray(Request $request): array { /** @var Purchase|null $purchase */ $purchase = $this->whenLoaded('trackable'); $user = $this->whenLoaded('user'); return [ 'id' => $this->id, 'purchase_id' => $this->trackable_id, 'attribute' => $this->attribute, 'old_value' => $this->old_value, 'new_value' => $this->new_value, 'changed_at' => $this->changed_at, 'actor_type' => $this->actor_type->value, 'purchase' => $purchase instanceof Purchase ? [ 'id' => $purchase->id, 'customer_name' => $purchase->nombre_apellido, 'status' => $purchase->status, ] : null, 'modified_by' => $user ? [ 'id' => $user->id, 'name' => $user->nombre_apellido, 'email' => $user->email, ] : null, ]; } }