Files
many-notes/app/Models/VaultNode.php

69 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships;
class VaultNode extends Model
{
use HasFactory;
use HasRecursiveRelationships;
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'is_file' => 'boolean',
];
}
/**
* The attributes that are mass assignable.
*
* @var string[]
*/
protected $fillable = [
'parent_id',
'is_file',
'name',
'extension',
'content',
];
/**
* Get the associated vault.
*/
public function vault(): BelongsTo
{
return $this->belongsTo(Vault::class);
}
/**
* Get the nodes for the vault.
*/
public function childs(): HasMany
{
return $this->hasMany(VaultNode::class, 'parent_id');
}
public function getCustomPaths(): array
{
return [
[
'name' => 'full_path',
'column' => 'name',
'separator' => '/',
'reverse' => true,
],
];
}
}