*/ use HasFactory; use HasRecursiveRelationships; use Searchable; /** * Get the associated vault. * * @return BelongsTo */ public function vault(): BelongsTo { return $this->belongsTo(Vault::class); } /** * Get the childs for the node. * * @return HasMany */ public function childs(): HasMany { return $this->hasMany(self::class, 'parent_id'); } /** * The nodes that are linked to the node. * * @return BelongsToMany */ public function links(): BelongsToMany { return $this->belongsToMany(self::class, null, 'source_id', 'destination_id'); } /** * The nodes that are backlinked to the node. * * @return BelongsToMany */ public function backlinks(): BelongsToMany { return $this->belongsToMany(self::class, null, 'destination_id', 'source_id'); } /** * The tags that are linked to the node. * * @return BelongsToMany */ public function tags(): BelongsToMany { return $this->belongsToMany(Tag::class, null, 'vault_node_id', 'tag_id'); } /** * Get the custom paths for the model. * * @return list */ public function getCustomPaths(): array { return [ [ 'name' => 'full_path', 'column' => 'name', 'separator' => '/', 'reverse' => true, ], ]; } /** * Get the indexable data array for the model. * * @return array */ public function toSearchableArray(): array { /** @var CarbonImmutable $updatedAt */ $updatedAt = $this->updated_at; return [ 'id' => (string) $this->id, 'vault_id' => (string) $this->vault_id, 'name' => $this->name, 'content' => (string) $this->content, 'updated_at' => $updatedAt->timestamp, ]; } /** * Determine if the model should be searchable. */ public function shouldBeSearchable(): bool { return (bool) $this->is_file; } /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'is_file' => 'boolean', ]; } }