Open saskaak opened 3 years ago
A workaround that worked for my use case:
$categories = Category::get()
->linkNodes()
->map(fn($category) => collect($category)->merge([
'parent' => $category->parent->uuid ?? null,
]));
With this I get a flat collection of all categories and each category has key parent
with just the UUID. The trick is to call collect($category)
, which unsets the parent
key, and then add it back using merge()
.
It would be nice if this was documented somewhere. It took a non-trivial amount of debugging for me to figure this out.
is this fixed? I think this is still is an issue
Copypasted from another issue:
The fix you provided makes impossibile to call parent relationship in toArray() or toJson() methods.... is there any official workaround for this? Or at least it should be clearly stated in the docs...Spent a hour debugging this, it's a major problem imho
Originally posted by @Silentscripter in https://github.com/lazychaser/laravel-nestedset/issues/17#issuecomment-284152396