- Dokumente-Plugin: Ordnerbaum mit vererbten Rechten und Sichtbarkeit, Hochladen per Ziehen und Ablegen, Versionen, Suche, Pagebuilder-Block - Organigramm aus den Vorgesetzten, Vorgesetzte im Admin pflegbar - Personensuche im Kopf übernimmt nur noch Suchbegriffe des Verzeichnisses Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Inhaus\Plugins\Documents\Models;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
#[Fillable(['folder_id', 'title', 'description', 'created_by', 'updated_by'])]
|
|
class Document extends Model
|
|
{
|
|
protected static function booted(): void
|
|
{
|
|
// Dateien aller Fassungen mit entfernen.
|
|
static::deleting(fn (Document $document) => $document->versions()->get()->each->delete());
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<DocumentFolder, $this>
|
|
*/
|
|
public function folder(): BelongsTo
|
|
{
|
|
return $this->belongsTo(DocumentFolder::class, 'folder_id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<DocumentVersion, $this>
|
|
*/
|
|
public function currentVersion(): BelongsTo
|
|
{
|
|
return $this->belongsTo(DocumentVersion::class, 'current_version_id');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<DocumentVersion, $this>
|
|
*/
|
|
public function versions(): HasMany
|
|
{
|
|
return $this->hasMany(DocumentVersion::class)->orderByDesc('version');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function updater(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'updated_by');
|
|
}
|
|
|
|
public function downloadUrl(?DocumentVersion $version = null): string
|
|
{
|
|
$version ??= $this->currentVersion;
|
|
|
|
return route('documents.download', ['document' => $this->id, 'version' => $version?->version, 'name' => $version?->name ?? 'datei']);
|
|
}
|
|
}
|