- 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>
51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Inhaus\Plugins\Documents\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Inhaus\Plugins\Documents\FolderTree;
|
|
|
|
#[Fillable(['parent_id', 'name', 'description', 'sort', 'created_by'])]
|
|
class DocumentFolder extends Model
|
|
{
|
|
protected static function booted(): void
|
|
{
|
|
static::saved(fn (DocumentFolder $folder) => FolderTree::flush($folder->wasRecentlyCreated || $folder->wasChanged('parent_id')));
|
|
static::deleted(fn () => FolderTree::flush(true));
|
|
}
|
|
|
|
/**
|
|
* @return array{0: string, 1: int}
|
|
*/
|
|
public function permissionResource(): array
|
|
{
|
|
return ['document_folder', $this->id];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<DocumentFolder, $this>
|
|
*/
|
|
public function parent(): BelongsTo
|
|
{
|
|
return $this->belongsTo(DocumentFolder::class, 'parent_id');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<DocumentFolder, $this>
|
|
*/
|
|
public function children(): HasMany
|
|
{
|
|
return $this->hasMany(DocumentFolder::class, 'parent_id')->orderBy('sort')->orderBy('name');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<Document, $this>
|
|
*/
|
|
public function documents(): HasMany
|
|
{
|
|
return $this->hasMany(Document::class, 'folder_id');
|
|
}
|
|
}
|