<?php  namespace App\Traits;  use App\Models\UserActivity; use Illuminate\Database\Eloquent\Relations\MorphMany;  trait HasUserActivity { 	public function activities(): MorphMany{}  	public function recordReadActivity(?bool $every = null, ?bool $update = null): self{}  	public function recordEveryReadActivity(): bool{}  	public function updateReadActivity(): bool{}  	public function getUserActivityTitle(): ?string{}  	public function getUserActivityUrl(): ?string{}  	public function shouldRecordUserActivity(int $type): bool{}  	protected static function bootHasUserActivity(): void 	{ 		static::deleting(function ($model): void { 			$model->activities->each(function ($item): void { 				$item->delete(); 			}); 		});  		static::created(function ($model): void { 			$user = auth()->user();  			if (!$user || !$model->shouldRecordUserActivity(UserActivity::TYPE_CREATE)) { 				return; 			}  			$model->activities()->create([ 				'user_id' => $user->id, 				'ip_address' => request()->ip() ?? null, 				'type' => UserActivity::TYPE_CREATE, 			]); 		});  		static::updated(function ($model): void { 			$user = auth()->user();  			if (!$user || !$model->shouldRecordUserActivity(UserActivity::TYPE_UPDATE)) { 				return; 			}  			$fields = $model->getChanges(); 			unset($fields[$model->getUpdatedAtColumn()]); 			$fields = array_keys($fields); 			sort($fields);  			$model->activities()->create([ 				'user_id' => $user->id, 				'ip_address' => request()->ip() ?? null, 				'type' => UserActivity::TYPE_UPDATE, 				'updated_fields' => $fields, 			]); 		}); 	} }