morphTo('deletable')->withTrashed(); } /** * Get the user that performed the deletion. */ public function deleter(): BelongsTo { return $this->belongsTo(User::class, 'deleted_by'); } /** * Create a new deletion record for the provided entity. */ public static function createForEntity(Entity $entity): self { $record = (new self())->forceFill([ 'deleted_by' => user()->id, 'deletable_type' => $entity->getMorphClass(), 'deletable_id' => $entity->id, ]); $record->save(); return $record; } public function logDescriptor(): string { $deletable = $this->deletable()->first(); if ($deletable instanceof Entity) { return "Deletion ({$this->id}) for {$deletable->getType()} ({$deletable->id}) {$deletable->name}"; } return "Deletion ({$this->id})"; } /** * Get a URL for this specific deletion. */ public function getUrl(string $path = 'restore'): string { return url("/settings/recycle-bin/{$this->id}/" . ltrim($path, '/')); } }