/** * Looper function that traverses all possible trails * * @param App\Note $note The current note (also a node) * @param boolean $isRoot Only given for the "start" note in index function * * @return Illuminate\Support\Collection A collection of all notes found */ public function getTrails($note, $isRoot = false) { $nextNotes = $note->next(); if (count($nextNotes) > 0) { if ($isRoot) { $nr = []; } else { $nr = new Collection(); } foreach ($nextNotes as $next) { if ($isRoot) { $nr[] = $this->getTrails($next)->prepend($note->id); } else { $nr = $nr->merge($this->getTrails($next)->prepend($note->id)); } } return $nr; } else { return new Collection($note->id); } }