Skip to content

Commit

Permalink
staudenmeir#259: Added attributes to be used with test
Browse files Browse the repository at this point in the history
  • Loading branch information
tylernathanreed authored Sep 6, 2024
1 parent 29c4de4 commit d1090c5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/Tree/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,31 @@ public function videosAndSelf(): MorphToManyOfDescendants
{
return $this->morphedByManyOfDescendantsAndSelf(Video::class, 'authorable');
}

/**
* @return Attribute<string, never>
*/
protected function displayPath(): Attribute
{
return Attribute::get(
fn (): string => (string) $this->ancestorsAndSelf
->reverse()
->reduce(function ($carry, $item) {
return $carry ? "{$carry} > {$item->name}" : $item->name;
}),
);
}

/**
* @return Attribute<string, never>
*/
protected function displayPathReverse(): Attribute
{
return Attribute::get(
fn (): string => (string) $this->ancestorsAndSelf
->reduce(function ($carry, $item) {
return $carry ? "{$carry} < {$item->name}" : $item->name;
}),
);
}
}

0 comments on commit d1090c5

Please sign in to comment.