Files
many-notes/app/Actions/GetPathFromVaultNode.php

29 lines
618 B
PHP

<?php
namespace App\Actions;
use App\Models\VaultNode;
class GetPathFromVaultNode
{
public function handle(VaultNode $node, bool $includeSelf = true): string
{
$relativePath = $node->parent ?
$node->parent->ancestorsAndSelf->last()->full_path . '/' :
'';
$path = sprintf(
'private/vaults/%u/%s/%s',
auth()->user()->id,
$node->vault->name,
$relativePath,
);
if ($includeSelf) {
$path .= $node->name . ($node->is_file ? '.' . $node->extension : '');
}
return $path;
}
}