3 namespace BookStack\Entities\Models;
5 use BookStack\Auth\User;
6 use BookStack\Interfaces\Loggable;
7 use Illuminate\Database\Eloquent\Model;
8 use Illuminate\Database\Eloquent\Relations\BelongsTo;
9 use Illuminate\Database\Eloquent\Relations\MorphTo;
12 * @property Model deletable
14 class Deletion extends Model implements Loggable
17 * Get the related deletable record.
19 public function deletable(): MorphTo
21 return $this->morphTo('deletable')->withTrashed();
25 * The the user that performed the deletion.
27 public function deleter(): BelongsTo
29 return $this->belongsTo(User::class, 'deleted_by');
33 * Create a new deletion record for the provided entity.
35 public static function createForEntity(Entity $entity): Deletion
37 $record = (new self())->forceFill([
38 'deleted_by' => user()->id,
39 'deletable_type' => $entity->getMorphClass(),
40 'deletable_id' => $entity->id,
47 public function logDescriptor(): string
49 $deletable = $this->deletable()->first();
51 return "Deletion ({$this->id}) for {$deletable->getType()} ({$deletable->id}) {$deletable->name}";
55 * Get a URL for this specific deletion.
57 public function getUrl($path): string
59 return url("/settings/recycle-bin/{$this->id}/" . ltrim($path, '/'));